C program-To calculate sin X = X – X 3 / 3! + X 5 / 5! – X7 / 7! +…….

Posted: January 19, 2012 in Lab 2

#include<stdio.h>
#include<math.h>
void sine(float*);
float fact(float);
void sine(float *x)
{
float i,j=0;
float sum=0;
for(i=1;i<8;i=i+2)
{
sum=sum+pow(-1,j++)*(pow(*x,i)/fact(i));
}
printf("%f",sum);
}
float fact(float i)
{
float f=1;
while(i>=1)
{
f=f*i;
i--;
}
return f;
}
void main()
{
float x;
printf("Enter x\n");
scanf("%f",&x);
sine(&x);
}
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