输入三个数并从大到小排列

//方法一
#include <stdio.h>
int main()
{
    int a,b,c,max,min;
    scanf("%d %d %d",&a,&b,&c);
    if(a > b)
    {
        max = a;
        min = b;
    }
    else
    {
        max = b;
        min = a;
    }

    if(c < min)
    {
        min = c;
    }
    if(c > max)
    {
        max = c;
    }
    printf("%d %d %d\n",max,a + b + c - max - min,min);
   
}


//方法二`
#include<stdio.h>
#include<math.h>
int main()
{
/从键盘输入三个整数x,y和z,按从大到小的顺序输出它们的值。/
int i;
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
if(x > y && y > z)
{
printf("%d\t%d\t%d\n",x,y,z);
}
if( y < z && z< x)
{
printf("%d\t%d\t%d\n",x,z,y);

}

if(x < y && y < z)
{
printf("%d\t%d\t%d\n",z,y,x);
}
if(y < z && y< x)
{
printf("%d\t%d\t%d\n",z,x,y);

}

if(x < y && y > z && z< x)
{
printf("%d\t%d\t%d\n",y,x,z);

}
if(y > z && z > x)
{
printf("%d\t%d\t%d\n",y,z,x);

}
return 0;
}


//方法三

```c
#include<stdio.h>
int main()
{
    int a,b,c;
    int 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\t%d\t%d\n",a,b,c);
    return 0;
}





  • 8
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 6
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值