Problem Description
输入一个正整数n(n<=10),计算
S=1!+2!+3!+...+n!
Input
输入一个正整数n(n<=10)(多组数据)
Output
输出S(每组数据一行)
Sample Input
2
Sample Output
3
#include<stdio.h> int main() { long int s,a; int i,n; while(scanf("%d",&n)!=EOF) { s=; a=; for(i=;i<=n;i++) { a=a*i; s=s+a; } printf("%ld\n",s); } return ; }
其他代码:
#include<stdio.h>
int ridsum(int n)
{
int sum,i;
if(n==||n==)
return ;
else
return ridsum(n-)*n;
}
int main()
{
int n,sum,i;
while(scanf("%d",&n)!=EOF)
{
for(i=,sum=;i<=n;i++)
sum+=ridsum(i);
printf("%d\n",sum);
}
return ;
}