Advertisement
abubaca

Untitled

Feb 16th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.28 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. long double fun(long double count, long double epsilon, long long &interation)
  7. {
  8.     long long n = 2;
  9.     long double result = 1, temp = -1 * count * count, dif;
  10.     dif = 1 + n*temp;
  11.     result = dif;
  12.     while (dif > epsilon)
  13.     {
  14.         n++;
  15.         temp *= -1 * count;
  16.         dif = n*temp;
  17.         result += dif;
  18.         n++;
  19.         temp *= -1 * count;
  20.         dif += n*temp;
  21.         result += dif;
  22.         if (dif < 0)
  23.             dif *= -1;
  24.     }
  25.     interation = n / 2;
  26.     return result;
  27. }
  28.  
  29. int main()
  30. {
  31.     setlocale(LC_ALL, "Russian");
  32.     const int str_wight = 16;
  33.     long double StartBoard, FinishBoard, Step, Epsilon;
  34.     cout << "Введите начало промежутка: ";
  35.     cin >> StartBoard;
  36.     cout << "Введите конец промежутка: ";
  37.     cin >> FinishBoard;
  38.     cout << "Введите шаг: ";
  39.     cin >> Step;
  40.     cout << "Введите Эпислон: ";
  41.     cin >> Epsilon;
  42.     cout << setw(20) << "Значение" << setw(20) << "Глубина итерации" << setw(20) << "Результат" << endl;
  43.     for (long double count = StartBoard; count <= FinishBoard; count += Step)
  44.     {
  45.         long long itr;
  46.         long double temp = fun(count, Epsilon, itr);
  47.         cout << setw(20) << count << setw(20) << itr << setw(20) << temp << endl;
  48.     }
  49.     system("pause");
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement