Advertisement
JewishCat

Teilor_26v

Dec 18th, 2015
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.40 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double cosx(double x)
  7. {
  8.     double n = 1.0;
  9.     double sum = 0.0;
  10.     int i = 1;
  11.  
  12.     do
  13.     {
  14.         sum += n;
  15.         n *= -1.0 * x * x / ((2 * i - 1) * (2 * i));
  16.         i++;
  17.     } while (fabs(n) > 0.00000000001);
  18.  
  19.     return sum;
  20. }
  21.  
  22. int main(int argc, char** argv) {
  23.  
  24.     double x = 1;
  25.     cout << cosx(x) << endl << cos(x) << endl;
  26.  
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement