Thursday, August 27, 2009

SIN

Formula : x-(x^3/3!)+(x^5/5!)-(x^7/7!)+...+(x^n/n!)
#include
#include
#include
void main()
{
float x=4,xt,f,s=0;
int i,j,n=4,v=1;
xt=x;
clrscr();
x=3.14/180*x;
for(i=1;i<=n;i+=2)
{
f=1;
for(j=1;j<=i;j++)
f=f*j;
s=s+pow(x,i)/f*v; /* v for sign + or -*/
v=v*-1;
}
printf("SIN %.2f is %.2f",xt,s);
getch();
}

Output
SIN 4.00 is 0.07

No comments:

Post a Comment