回覆列表
-
1 # 熱心市民小劉
-
2 # 現在答題全靠運氣的
參考程式碼:
if(a>b && a>c)
max=a;
else if(b>a && b>c)
max=b;
else if(c>a && c>b) (測試,可以直接寫個else)
max=c;
if(a<b && a<c)
min=a;
else if(b<a && b<c)
min=b;
else if(c<a && c<b)
min=c;
if(a>b && a<c)
mid=a;
else if(b>a && b<c)
mid=b;
else if(c>a && c<b)
mid=c;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int n1, n2, n3;
Console.WriteLine("請輸入三個整數,以回車分隔:");
n1 = Convert.ToInt32(Console.ReadLine());
n2 = Convert.ToInt32(Console.ReadLine());
n3 = Convert.ToInt32(Console.ReadLine());
if (n1 < n2)
{
n1 ^= n2;
n2 ^= n1;
n1 ^= n2;
}
if (n2 < n3)
{
n2 ^= n3;
n3 ^= n2;
n2 ^= n3;
}
if (n1 < n2)
{
n1 ^= n2;
n2 ^= n1;
n1 ^= n2;
}
Console.WriteLine("排序後:" + n1 + " " + n2 + " " + n3);
}
}
}