##题目描述
求1+2!+3!+...+N!的和
##输入描述
正整数N(N〈=20)
##输出描述
1+2!+3!+...+N!的和
for :
# include <stdio.h>
int main(void)
{
long int n = 0;
long int i = 0;
long int m = 1;
long int sum=0;
scanf("%ld", &n);
for (i=1; i<=n; ++i)
{
m = m * i;
sum = sum +m;
}
printf ("%ld\n", sum);
return 0;
}
while - for:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
int i;
long long int a;
long long int sum;
while ((scanf("%d", &n)) != EOF && n <= 50)
{
for (a = 1.0, sum = 0.0, i = 1; i <= n; i++)
{
a = a * i;
sum += a;
}
printf("%lld\n", sum);
}
return 0;
}