zero_shubham1

sin

Jan 24th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. double factorial(double n){
  5.     if(n==0)
  6.         return 1;
  7.     return (n * factorial(n-1.0));
  8. }
  9.  
  10. int main(){
  11.     int i=1,flag=1;
  12.     double sinx,term, x= (M_PI/2);
  13.     while(i<=1000){
  14.  
  15.         term =(double) (powl(x,(double)i)/factorial((double)i));
  16.  
  17.         if(flag==1){
  18.             sinx += term;
  19.             flag=0;
  20.         }else{
  21.             sinx -= term;
  22.             flag=1;
  23.         }
  24.  
  25.         i += 2;
  26.     }
  27.  
  28.     printf("sinx=>%f \nsin=>%f\n",sinx,sin(x));
  29.     return 1;
  30. }
Add Comment
Please, Sign In to add comment