SHARE
TWEET

Untitled

a guest Jun 26th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. static long fat = 1; // fat(2*0)
  5.  
  6. int main()
  7. {
  8.   int n, i, j;
  9.   double x, z = 0.0;
  10.  
  11.   scanf("%lf%d", &x, &n);
  12.  
  13.   for (i = 0; i < n; i++ )
  14.   {
  15.     printf("* i=%d fat(%d)=%dn", i, 2*i, fat);
  16.     z = z + ( ( pow(-1.0 , i)*pow(x, (2.0*i)) ) / fat );
  17.     fat = fat * (2*i+1) * (2*i+2); // proximo fat
  18.   }
  19.  
  20.   printf("nncos(x) = %lfn", z );
  21.  
  22.   return 0;
  23. }
  24.      
  25. [~/Projects/testes/so]
  26. $./377309
  27. 3 5
  28. * i=0 fat(0)=1
  29. * i=1 fat(2)=2
  30. * i=2 fat(4)=24
  31. * i=3 fat(6)=720
  32. * i=4 fat(8)=40320
  33.  
  34. cos(x) = -0.974777
  35.  
  36. [~/Projects/testes/so]
  37. $
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top