Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- double factorial(double n){
- if(n==0)
- return 1;
- return (n * factorial(n-1.0));
- }
- int main(){
- int i=0,flag=1;
- double cosx,term, x= (M_PI/4);
- while(i<=1000){
- term =(double) (powl(x,(double)i)/factorial((double)i));
- if(flag==1){
- cosx += term;
- flag=0;
- }else{
- cosx -= term;
- flag=1;
- }
- i += 2;
- }
- printf("cosx=>%f \ncos=>%f\n",cosx,cos(x));
- return 1;
- }
Add Comment
Please, Sign In to add comment