class Program { public void dayin() { Console.WriteLine("hollo world"); } /// <summary> /// 累加求和 /// </summary> /// <param name="n"></param> /// <returns></returns> public int leijia(int n) { int sum = 0; for (int i = 1; i <= n;i++ ) { sum += i; } return sum; } /// <summary> /// 输入一个数判断是不是质数 /// </summary> /// <param name="n"></param> /// <returns></returns> public void zhishu(int n) { int count = 0; for (int i = 1; i <= n;i++ ) { if(n%i==0) { count++; } } if (count == 2) { Console.WriteLine("质数"); } else { Console.WriteLine("不是质数"); } } /// <summary> /// 求阶乘及其的和 /// </summary> /// <param name="n"></param> /// <returns></returns> public void jiecheng(int n) { int jiecheng = 1; int he = 0; for (int i = 1; i <=n; i++) { jiecheng *= i; he = he + jiecheng; } Console.WriteLine("阶乘是"+jiecheng+"阶乘的和是"+he); } /// <summary> /// 猜拳三局两胜 /// </summary> /// <param name="a"></param> /// <param name="b"></param> public void caiquan() { int renying = 0; int diannaoying = 0; for (int i = 1; i <= 3; i++) { Console.Write("请输入人出拳(0-剪刀,1-石头,2-布)a="); int a = int.Parse(Console.ReadLine()); Random r = new Random(); int b = r.Next(3); Console.WriteLine("电脑出拳(0-剪刀,1-石头,2-布)b=" + b); if (a - b == 1 || a - b == -2) { renying++; Console.WriteLine("人赢一局"); } else if (a == b) { Console.WriteLine("平局"); i--; continue; } else { diannaoying++; Console.WriteLine("电脑赢一局"); } if (renying >= 2) { Console.WriteLine("三局两胜人赢"); break; } else if (diannaoying >= 2) { Console.WriteLine("三局两胜电脑赢"); break; } } } //主函数 static void Main(string[] args) { while (true) { new Program().dayin(); Console.WriteLine("请输入一个正整数"); int n = int.Parse(Console.ReadLine()); int jieguo = new Program().leijia(n); Console.WriteLine(jieguo); new Program().zhishu(n); new Program().jiecheng(n); new Program().caiquan(); Console.ReadLine(); } } }