1. 程式人生 > >將三個數從

將三個數從

將三個數按從小到大輸出
#define _CRT_SECURE_NO_WARNINGS //巨集定義
#include <stdio.h>
#include <windows.h>
int main()
{
int a ,b,c,t; //定義四個整型變數,t為臨時變數
printf(“輸入三個數字”);//任意輸入三個整數
scanf("%d%d%d", &a, &b, &c);
if (a < b)
{
t= a;
a = b;
b = t; //如果a<b,a和b借用t交換位置,
}

if (a>c)
{
	t= a;
	a = c;
	c = t;                                //如果a>c,a和c交換位置 
}
if (b > c)
{
	t = b;
	b = c;
	c = t;                               //如果b>c,b和c交換位置
}
printf("%d%d%d", a,b,c);    //列印a,b,c,此時a,b,c已經是從小到大的序列
	system("pause");
return 0;

}