Program for taylor series of Sin x.

#include <stdio.h>
#include <math.h>
#define pi 3.142857

double fact(double n)
{
if(n==1)
return 1;
return(n*fact(n-1));
}

main()
{
double n,rad=0.0174;
int x;
double sine(double);
/* for(x=0;x<=90;x++)
{
rad=x*pi/180;
n=sine(rad);
printf("For %lf radians i.e %d degree sine value is: %.2lf",rad,x,n);
}*/
for(;rad<=1.57;rad+=0.1)
{
n=sine(rad);
printf("For %lf radians sine value is : %.2lf",rad,n);
}
}

double sine(double x)
{
double value=x,unit=1,odd=3;
int count=1;

while(unit>0.009)
{
count++;
unit=pow(x,odd)/fact(odd);
if(unit>0.009)
if(count%2)
value=value+unit;
else
value=value-unit;
odd+=2;
}
printf(" No. of Iterations %d\n",count);
return(value);
}

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