标签:ota int alt mes print http c89 images include
求(即求1!+2!+3!+4!+…+20!)。
阶乘求和 n!=1×2×3×...×n或者0!=1,n!=(n-1)!×n
#include<stdio.h>
int main()
{
int n, num, total;
total = 0;
for (n=1; n <= 20;n++)
{
num = 1; //这个赋值要放循环里面不然后面每次循环都不会从1开始
for (int a = 1; a <= n;a++)
{
num *= a; //阶乘的意思是 n位数=1x2x3x4x...xn
}
total += num; //把每位数的阶乘累加起来
}
printf("%d", total);
return 0;
}
标签:ota int alt mes print http c89 images include
原文地址:https://www.cnblogs.com/old-horse/p/12493292.html