Advertisement
Toliak

kek 12

Dec 20th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     double epsilon;
  9.     cout << "Enter epsilon: ";
  10.     cin >> epsilon;
  11.  
  12.     double x;
  13.     cout << "Enter X: ";
  14.     cin >> x;
  15.  
  16.     int iterations = 1;
  17.     double prev = 0;
  18.     double current = x;
  19.     while (fabs(current - prev) > epsilon) {
  20.         prev = current;
  21.         current *= (1 - (x * x) / (iterations * iterations * M_PI * M_PI));
  22.  
  23.         iterations++;
  24.     }
  25.  
  26.     cout << "Iterations: " << iterations << endl;
  27.     cout << "Result: " << current << endl;
  28.     cout << "Fact difference: " << fabs(current - sin(x)) << endl;
  29.  
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement