萌新提问,求大佬解答~
问题:编写程序计算的e^x值,公式如下=
e^x = 1+x+x^2/2!+x^3/3!+...+x^n/n!
要求循环跳出条件为x^n/n!<0.000001
我编写的代码是这样的;
#include <stdio.h>
#include <math.h>
int main()
{
int iCounter = 1;
long int factorial = 1;
double x;
double result = 1;
double text;
double temp;
printf("Please input the x:");
scanf_s("%lf", &x);
text = exp(x);
do
{
factorial = 1 * iCounter*factorial;
result = result + pow(x, iCounter) / factorial;
iCounter++;
temp = pow(x, iCounter - 1) / factorial > 0.000001;
} while (pow(x, iCounter - 1) / factorial > 0.000001);
printf("result = %f,text = %f\n", result,text);
getchar();
return 0;
}
如果有大佬帮忙的话,万分感激,我debug好久