Archived
1
0
This repository has been archived on 2026-03-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
SomeLab/C Sharp 1_4/Program.cs
2025-10-24 17:19:46 +08:00

40 lines
1.1 KiB
C#

using System;
using static System.Math;
namespace C_Sharp_1_4
{
public class Program
{
static void Main()
{
int a, b, c, a1, b1, c1, temp, max, min, medium;
Random rNumber = new Random();
a = rNumber.Next(101);
b = rNumber.Next(101);
c = rNumber.Next(101);
a1 = a; b1 = b; c1 = c;
Console.WriteLine("原始值: a={0}, b={1}, c={2}");
// 方法一
if (a > b)
{
temp = a; a = b; b = temp;
}
if (a > c)
{
temp = a; a = c; c = temp;
}
if (b > c)
{
temp = b; b = c; c = temp;
}
Console.WriteLine("第一种方法排序: a={0}, b={1}, c={2}", a, b, c);
// 方法二
a = a1; b = b1; c = c1;
max = Max(a, Max(b, c));
min = Min(a, Min(b, c));
medium = a + b + c - max - min;
Console.WriteLine("第二种方法排序: a={0}, b={1}, c={2}", min, medium, max);
}
}
}