Thursday 26 April 2012

To find cose(x),sine(x),e^x of a number

#include<stdio.h>
main()
{
int n,x,y;
double z,ts,tc,ss,sc,pi,xy,xz;
pi=3.141592654;
printf("enter the angle");
scanf("%d",&x);
z=x*(pi/180);
ss=z;
sc=1;
ts=z;
tc=1;
xy=1;
xz=1;
for(n=1;n<=1000;n++)
  {
ts=-1*ts*z*z/(2*n*(2*n+1));
ss=ss+ts;
tc=-1*tc*z*z/(2*n*(2*n-1));
sc=sc+tc;
xy=xy*x/n;
xz=xz+xy;
}
printf("sin(%d)=%f\n",x,ss);
printf("cos(%d)=%f\n",x,sc);
printf("exponential of %d(e^%d)= %f\n",x,x,xz);
}

No comments:

Post a Comment