using System; using System.Collections.Generic; using System.Text; namespace ExSum { class Sum { public long sum(int num) { long sum = 0; for (int i = 1; i <= num; i++) { long f = 1; //求i的i次方 for (int j = 1; j <= i; j++) { f *= i; } sum += f; } return sum; } static void Main(string[] args) { Console .Write("請輸入一個整數:"); int num=Convert.ToInt32 (Console.ReadLine()); Sum s=new Sum(); Console.WriteLine("1的1次方到{0}的{1}次方的和為{2}", num,num,s.sum (num)); } } }