解题思路:
int 超范围,用unsigned int
注意事项:
参考代码:
#include<stdio.h>
unsigned long int f(unsigned long int n)
{
unsigned long int i;
unsigned long int factorial=1;
if(n > 1)
{
for (i = 1; i <=n; i++)
{
factorial = factorial * i;
}
return f(n - 1) + factorial;
}
else
{
return 1;
}
}
int main()
{
unsigned long int n;
while (~scanf("%d", &n))
{
printf("%lu\n", f(n));
}
return 0;
}
0.0分
0 人评分