打印n的階乘之和

        static void Main(string[] args)
        {
            int n = Convert.ToInt32(Console.ReadLine());  
            int sum = 0;
            for (int i = 1; i <= n; i++)
            {              
                sum+=h(i);            
            }
            Console.WriteLine(sum);
        }
        static int h(int i)
        {
            if (i == 1)
            {
                return 1;
            }
            else
            {              
                return  h(i - 1) * i;
            }
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章