黄迪明3.8
来源:互联网 发布:linux chown chgrp 编辑:程序博客网 时间:2024/05/12 12:51
/*编写一个程序计算e^x=1+x+x^2/2!+x^3/3!+x^4/4!+…+x^n/n!*/#include<stdio.h>#include<stdlib.h>int main() { double ex = 1, temp1 = 1, temp2 = 1, x; int n, i, j; printf("Please input x and n:"); scanf("%lf %d", &x, &n); for (i = 1; i <= n; i++) { for (j = 1; j <= i; j++) { temp1 = temp1*x;//计算分子 temp2 = temp2*j;//计算分母 } ex = ex + temp1 / temp2; } printf("%lf\n", ex); system("pause"); return 0; }
0 0