i've just started learning C language from two weeks ago (and its the first programming language that i learn!!)
i have to do the following assignment:
Write a program that computes the value of e^x by using the formula:
e^x = 1 + x/1! + x^2 / 2! + x^3 / 3! +.......
i wrote the following program but i keep receiving error!
#include <stdio.h>
#include <math.h>
int main ()
{
float x, result,fact=1; int power=0,a=1;
printf ("Enter the value of X");
scanf ("%f",&x);
result= 0;
fact=power;
while (power <= 3){
++power;
while ( (power-a) >= 1){
fact= fact * (power-a);
++a;
}
result = (result + pow(x,power)) / fact;
if (power >= 3) {
printf ("the result is %f",result + 1);
break;
}
}
return 0;
}
thanx for any help and sorry for my bad english.