新手小白求解n的阶乘之和的问题!
新手小白求解n的阶乘之和的问题!当输入n为6时,结果为什么是1!+2!+…+6!=8?using System;
namespace 实验EX1_1
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入正整数n");
String str = Console.ReadLine();
int n = Convert.ToInt32(str);
int sum = 0,i,j;
for (i = 1; i <= n; i++) ;
{
int flag = 1;
for (j = 0; j <= i; j++) ;
{
flag *= j;
}
sum += flag;
}
Console.WriteLine("1!+2!+...+{0}!={1}", n, sum);
Console.ReadLine();
}
}
}