三整数排序

ICPC--1022: 三整数排序

题目描述

从键盘输入三个整数x,y和z,按从大到小的顺序输出它们的值。

输入

输入三个整数x,y和z。

输出

按从大到小的顺序输出它们的值。

样例输入

20 16 18

样例输出

20 18 16

提示

...

代码

#include

int main(void)
{
    int a, b, c, temp;

    scanf_s("%d%d%d", &a, &b, &c);

    if (a < b) //若a>b,则交换a和b中内容
    {
        temp = a; //将a中内容咱存入temp
        a = b; //将b中内容存入a中
        b = temp; //将temp中内容存入b中
    }

    if (a < c) //若a>c,则交换a和c中内容
    {
        temp = a; //将a中内容咱存入temp
        a = c; //将c中内容存入a中
        c = temp; //将temp中内容存入c中
    }

    if (b < c) //若b>c,则交换b和c中内容
    {
        temp = b; //将b中内容咱存入temp
        b = c; //将c中内容存入b中
        c = temp; //将temp中内容存入c中
    }

    printf("%d %d %d
", a, b, c);
    return 0;
}
发表评论
留言与评论(共有 0 条评论) “”
   
验证码:

相关文章

推荐文章