写一个C语言程序求e^x=1+x+x^2/2!
时间: 2023-10-22 12:03:58 浏览: 161
用C语言编程:用公式计算:e≈1+1/1!+1/2! …+1/n!,精度为10-6
5星 · 资源好评率100%
以下是可以求e^x=1+x + x^2/2!的C语言程序:
#include <stdio.h>
#include <math.h>
int main()
{
float x, answer = 0, term = 1;
int i;
printf("Enter the value of x: ");
scanf("%f", &x);
for (i = 1; i <= 10; i++)
{
answer += term;
term *= (x / i);
}
printf("The value of e^%.2f = %f", x, answer);
return 0;
}
阅读全文