求1到任意整数的阶乘之和 例如(1!+2!+3!+~~~+n!)

时间:2021-03-03 11:26:59

 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;
        }
    }

}