using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 练习2 { class Program { static void Main(string[] args) { //输入3个数,将这三个数从大到小排列打印出来; Console.Write("请输入第一个数:"); int a =Convert .ToInt32 (Console.ReadLine ()); Console.Write("请输入第二个数:"); int b = Convert.ToInt32(Console .ReadLine ()); Console.Write("请输入第三个数:"); int c = Convert.ToInt32(Console .ReadLine ()); if (a >= b && a >= c) { if (b >= c) { Console.WriteLine(a); Console.WriteLine(b); Console.WriteLine(c); } else { Console.WriteLine(a); Console.WriteLine(c); Console.WriteLine(b); } } if (b >= a && b >= c) { if (a >=c) { Console.WriteLine(b); Console.WriteLine(a); Console.WriteLine(c); } else { Console.WriteLine(b); Console.WriteLine(c); Console.WriteLine(a); } } if (c >= b && c >= a) { if (b >= a) { Console.WriteLine(c); Console.WriteLine(b); Console.WriteLine(a); } else { Console.WriteLine(c); Console.WriteLine(a); Console.WriteLine(b); } } Console.ReadLine(); } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 课后题2 { class Program { static void Main(string[] args) { //打印100以内的全部质数,并求和 int count = 0; int sum = 0; for (int i = 1; i <= 100; i++) { count = 0; //判断当前数是否是质数 //质数就是只能被1和自身整除的数 for (int j = 1; j <= i; j++) { if (i % j == 0) { count++; } } if (count == 2) { Console.Write(i + ","); sum += i; } } Console.ReadLine(); } } }
时间: 2024-10-09 04:53:21