已知函数ex可以展开为幂级数1+x+x2/2!+x3/3!+⋯+xk/k!+⋯。现给定一个实数x,要求利用此幂级数部分和求ex的近似值,求和一直继续到最后一项的绝对值小于0.00001。
输入格式:
输入在一行中给出一个实数x∈[0,5]。
输出格式:
在一行中输出满足条件的幂级数部分和,保留小数点后四位。
输入样例:
1.2
结尾无空行
输出样例:
3.3201
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
double n,t;
scanf("%lf",&n);
t=exp(n);
printf("%.4f",t);
return 0;
}