Guest User

Untitled

a guest
Oct 9th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double fact(double x)
  5. {
  6.     if (!x)
  7.         return 1;
  8.  
  9.     return (fact(x - 1) * x);
  10. }
  11.  
  12. double sinx(double x)
  13. {
  14.     const unsigned int N = 50;
  15.  
  16.     double result = 0;
  17.     unsigned int n;
  18.     for (n = 1; n <= N; ++n)
  19.         result += ((pow(-1, n + 1) * pow(x, 2 * n - 1))
  20.                                     / fact(2 * n - 1));
  21.  
  22.     return result;
  23. }
  24.  
  25. int main()
  26. {
  27.     double sx = sinx(0.8);
  28.     printf("%f \n", sx);   
  29.    
  30.     return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment