标签:i++ with clu 计算 pre printf for exit std
计算1!+2!+…+100!
程序核心——累积累乘的两个循环
#include<stdio.h>
double fact(int n);
int main()
{
int i;
double sum;
sum=0;
for(i=1;i<=100;i++)
sum=sum+fact(i);
printf("1!+2!+…+100!=%e\n",sum);
return 0;
}
double fact(int n)
{
int i;
double result;
result=1;
for(i=1;i<=n;i++)
result*=i;
return result;
}
1!+2!+…+100!=9.426900e+157
--------------------------------
Process exited after 0.2632 seconds with return value 0
请按任意键继续. . .
重点:循环与函数的结合
标签:i++ with clu 计算 pre printf for exit std
原文地址:https://www.cnblogs.com/5236288kai/p/10660801.html