using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 函数阶乘累加和 { class Program { //没有返回值,没有参数 public void jiehe() { Console.Write("请输入一个整数:"); int a = int.Parse(Console.ReadLine()); int sum = 0; int jie = 1; for (int i = 1; i <= a; i++) { jie *= i; sum += jie; } Console.WriteLine(sum); } //没有返回值,有参数 public void jiehe(int z) { int sum = 0; int jie = 1; for (int i = 1; i <= z; i++) { jie *= i; sum += jie; } Console.WriteLine(sum); } //有返回值,没有参数 public int jiehe1() { Console.Write("请输入一个整数:"); int a = int.Parse(Console.ReadLine()); int sum = 0; int jie = 1; for (int i = 1; i <= a; i++) { jie *= i; sum += jie; } return sum; } //有返回值,有参数 public int jiehe2(int z) { int sum = 0; int jie = 1; for (int i = 1; i <= z; i++) { jie *= i; sum += jie; } return sum; } static void Main(string[] args) { //阶乘累加求和 Program hanshu = new Program(); //没有返回值,没有参数 //hanshu.jiehe(); //没有返回值,有参数 //Console.Write("请输入一个整数:"); //int a = Convert.ToInt32(Console.ReadLine()); //hanshu.jiehe(a); //有返回值,没有参数 //int sum = hanshu.jiehe1(); //Console.WriteLine(sum); //有返回值,有参数 Console.Write("请输入一个整数:"); int a = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(hanshu.jiehe2(a)); Console.ReadLine(); } } }