Expansion of sin(x) with a limit(n)
#include<stdio.h>#include<conio.h>#include<math.h>int fact(int);void main(){int x,n,k,i;float s=0;printf("Enter x and n");scanf("%d%d",&x,&n);for(i=0;i<n;i++){k=fact(i*2);if(i%2==0)s=s+(float)(pow(x,i*2)/k);elses=s-(float)(pow(x,i*2)/k);}printf("sum is %f",s);getch();}int fact(int a){int f=1,j;for(j=1;j<=a;j++)f=f*j;return(f);}
0 Comments:
Post a Comment