Derga

Untitled

Oct 9th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. double pow(double number, int power)
  2. {
  3.     double result = 1;
  4.     for (int i = 1; i <= power; i++)
  5.     {
  6.         result *= number;
  7.     }
  8.     return result;
  9. }
  10.  
  11. void Solution2(const double& x, const double& alpha)
  12. {
  13.     bool is_accuracy_exist = false;
  14.     double accuracy = DBL_MAX;
  15.     int iterationIndex = 0;
  16.     double summ = 0;
  17.     while (abs(alpha) < accuracy) {
  18.         double summand = pow(x, iterationIndex * 2 + 1) / (iterationIndex * 2 + 1);
  19.         if (summ != 0) {
  20.             accuracy = abs(summand) / abs(summ);
  21.             is_accuracy_exist = true;
  22.         }
  23.         summ += summand;
  24.  
  25.         cout << setprecision(15) << "Номер итерации: " << iterationIndex << endl
  26.             << "Последний просуммированный член ряда: " << summand << endl
  27.             << "Текущая частичная сумма: " << summ << endl;
  28.         if (is_accuracy_exist) {
  29.             cout << "Точность вычисления заданной текущей частичной суммы: " << accuracy << endl;
  30.         }
  31.     }
  32. }
Add Comment
Please, Sign In to add comment