Thursday, August 27, 2009

COS

Formula : 1-(x^2/2!)+(x^4/4!)+(x^6/6!)+...+(x^n/n!)
#include
#include
#include
void main()
{
float x=4,xt,f,s=0;
int i,j,n=4;
xt=x;
clrscr();
x=3.14/180*x;
for(i=2;i<=n;i+=2)
{
f=1;
for(j=1;j<=i;j++)
f=f*j;
s=s+pow(x,i)/f;
}
printf("COS %f is %f",xt,1-s);
getch();
}
Output
COS 4.000000 is 0.997565

No comments:

Post a Comment