9. WAP to calculate series :- sin X = X – X 3 / 3! + X 5 / 5! – X7 / 7! +…….

Posted: August 26, 2012 in CSE Sem1, Lab 7
#include<stdio.h>
#include<math.h>
int main()
{
float sin=0,x,fact;
int i,j,f=-1;
printf("Enter x:");
scanf("%f",&x);
for(i=1;i<10;i+=2)
{
fact=1;
for(j=1;j<=i+2;j++)
fact=fact*j;
sin=sin+(f*pow(x,i+2))/fact;
if(f>0)
f=-1;
else
f=1;
}
printf("\n\nsinX=%f",x+sin);
return 0;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s