求c程序:用循环嵌套的方法求阶乘的和!
求c程序:用循环嵌套的方法求阶乘的和!1!+2!+3!+***+20!
[[it] 本帖最后由 andy198719 于 2008-9-24 00:45 编辑 [/it]]
/******************************************************************************* 求c程序:用循环嵌套的方法求阶乘的和! 1!+2!+3!+***+20! *******************************************************************************/ #include<stdio.h> int main(void) { int i,j; double sum=0.0,sumx; for(i=1;i<=20;i++) { for(sumx=1.0,j=i;j>0;j--) sumx*=j; sum+=sumx; } printf("%.0lf\n",sum); getch(); }
#include<stdio.h> int main(void) { int i, j; double sum = 0.0, sumx = 1.0; for (i = 1; i <= 20; i++) { sumx *= i; sum += sumx; } printf("%.f\n", sum); for (sum = 1.0, i = 1;i <= 20;i++) { for (sumx = 1.0, j = i;j > 0;j--) sumx *= j; sum += sumx; } printf("%.f\n", sum); return 0; }
#include<stdio.h> int main(void) { int i; long long sum = 0, sumx = 1; for (i = 1; i <= 20; i++) { sum += sumx *= i; printf("%d:%lld - %lld\n", i, sumx, sum); } printf("%lld\n", sum); return 0; }