1. 程式人生 > >將三個數按從大到小輸出

將三個數按從大到小輸出

建立第四個變數,然後兩兩比較。程式碼如下:

#include<stdio.h>
int main()
{
	int a = 0;
	int b = 0;
	int c = 0;
	int t = 0;            //創鍵第四個變數
	printf("請任意輸出三個數:");
	scanf("%d%d%d", &a, &b, &c );
	if(a<b)
	{
		t = a;
		a = b;
		b = t;
	}
    if(a<c)
	{
		t = a;
		a = c;
		c = t;
	}
	if(b<c)
	{
		t = b;
		b = c;
		c = t;
	}
	printf("從大到小排序為:%d %d %d", a, b, c);

	return 0;
}