kirya_shkolnik

Кама - 1

Apr 6th, 2021 (edited)
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.45 KB | None | 0 0
  1. #include <iostream>
  2. #define _USE_MATH_DEFINES
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double Calc(double epsilon){
  7.     double a = 1.0;
  8.     int i = 1;
  9.     double res = 0.0;
  10.     while(abs(a) > epsilon){
  11.         res+=a;
  12.         a= - a * ( (2.0*i-1.0) / (2.0*i+1.0) );
  13.         i++;
  14.     }
  15.     return res;
  16. }
  17. int main() {
  18.     double epsilon,res;
  19.     cin >> epsilon;
  20.     res = Calc(epsilon);
  21.     cout << res;
  22.     cout << endl <<  M_PI / 4 ;
  23. }
Add Comment
Please, Sign In to add comment