求1到任意整數的階乘之和 例如(1!+2!+3!+~~~+n!)
阿新 • • 發佈:2019-02-11
using System;
using System.Collections.Generic;
using System.Text;
namespace Text
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
Console .WriteLine (p.GetSum(3));
}
private int GetSum(int x)
{
int sum = 0;
for (int i = 1; i <= x; i++)
{
int t = 1;
for (int j = 1; j <= i; j++)
{
t = t * j;
}
sum += t;
}
return sum;
}
}
}