Advertisement
Guest User

algo_1

a guest
Apr 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. //#include "stdafx.h"
  2. #include <iostream>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     double epsilon = pow(10,-6.0);
  8.  
  9.     int k = 1;
  10.  
  11.     double exact_value = pow(2, 0.5) / 2;
  12.  
  13.     std::cout << "exact value: " << exact_value << std::endl;
  14.  
  15.     double mult = 1+ (  pow(-1,1)/((2*1)+1) );
  16.  
  17.     while (  fabs(  fabs(mult) - fabs(exact_value)  )  > epsilon )
  18.     {
  19.         k++;
  20.         mult *= 1+ (  pow(-1,k)/((2*k)+1)  );        
  21.     }
  22.  
  23.     std::cout << "We need to take " << k << " multipliers." << std::endl;
  24.  
  25.     return 0;
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement