Code using System; using System.Collections.Generic; using System.Text;
namespace ExSum { class Sum { publiclong 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; } staticvoid 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)); Console.ReadLine(); } } }