C语言_利用求阶乘函数Fact(),编程计算1!+2!+...+n!

【C语言_利用求阶乘函数Fact(),编程计算1!+2!+...+n!】利用求阶乘函数Fact(),编程计算1!+2!+…+n!

#include unsigned long Fact(unsigned int n); //函数原型声明int main () { int n,p; unsigned long sum = 0; printf("Input n:"); scanf("%d",&n); for(int i = 1; i<= n; i++) { printf("%d!",i); if (i != n) printf(" + "); else printf(" = "); sum += Fact(i); } printf("%lu",sum); return 0; } //用迭代法计算n! unsigned long Fact(unsigned int n) { unsigned int i; unsigned long result = 1; for(i=2; i<=n; i++) result *= i; return result; }

    推荐阅读