用数组保存三个数:
static void Main(string[] args)
{
Console.WriteLine("输入3个数:");
int[] a = new int[3];
for (int b = 0; b < a.Length; b++) //用for循环给数组添加数据
{
a[b] = int.Parse(Console.ReadLine()); //接收3个数
}
int temp; //保存最大值
for (int i = 1; i < a.Length; i++)
{
for (int j = 0; j < a.Length - i; j++)
{
if (a[j] > a[j + 1])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
foreach (int c in a) //用foreach输出排序后的数组元素
{
Console.WriteLine(c);
}
}