方法一
#include<stdio.h>
int main(){
int a,i,n,sum,b;
printf("请输入:");
scanf("%d",&a);
for(n=1;n<=a;n++)
{
int b=1;
for(i=1;i<=n;i++)
{
b=b*i;
}
sum=sum+b;
}
printf("结果为:%d",sum);
return 0;
}
方法二
#include<stdio.h>
int main(){
int sum,i,b=1,a;
printf("请输入:");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
b=b*i;
sum=sum+b;
}
printf("结果为:%d",sum);
return 0;
}
标签:两种,return,int,sum,形式,includeint,printf,阶乘 From: https://www.cnblogs.com/cocear/p/16912290.html