int sum = 0;
Console.Write("请输入数字:");
int shu = int.Parse(Console.ReadLine());
for (int i = 1; i <= shu; i++)//从1开始遍历
{
int jiecheng = 1;
//求i的阶乘
for (int j = 1; j <= i; j++)
{
jiecheng = jiecheng*j;
}
sum = sum + jiecheng;//累加
}
Console.WriteLine("结果为:" + sum);