例題1-5 三整數排序《算法入門競賽經典第二版》

輸入3個整數,從小到大排序後輸出。
樣例輸入:
20 7 33
樣例輸出:
7 20 33

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);
    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;
    }
    printf("%d%d%d",c,b,a);
    return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章