zero_shubham1

cos

Jan 24th, 2019
121
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=0,flag=1;
  12.     double cosx,term, x= (M_PI/4);
  13.     while(i<=1000){
  14.  
  15.         term =(double) (powl(x,(double)i)/factorial((double)i));
  16.  
  17.         if(flag==1){
  18.             cosx += term;
  19.             flag=0;
  20.         }else{
  21.             cosx -= term;
  22.             flag=1;
  23.         }
  24.  
  25.         i += 2;
  26.     }
  27.  
  28.     printf("cosx=>%f \ncos=>%f\n",cosx,cos(x));
  29.     return 1;
  30. }
Add Comment
Please, Sign In to add comment