Thursday, August 27, 2009

e^x

Formula : 1+(x/1!)+(x^2/2!)+(x^3/3!)+...+(x^n/n!)
#include
#include
#include
void main()
{
float x=4,x1=x,f,s=0;
int i,j,n=4;
clrscr();
x=3.14/180*x;
for(i=1;i<=n;i++)
{
f=1;
for(j=1;j<=i;j++)
f=f*j;
s=s+pow(x,i)/f;
}
printf("\ne^x %.2f is %.2f",x1,s);
getch();
}
Output
e^x 4.00 is 0.07

No comments:

Post a Comment