输入 a,b,c三个整数,按从小到大的顺序输出。(练习题四)

输入 a,b,c三个整数,按从小到大的顺序输出。

这个题有挺多解
我写了两种题解
第二种参考了大佬的写法

题解一:

#include
#include
int main()
{int a,b,c,t;
  printf("请输入整数a, b, c");
  scanf("%d %d %d", &a,&b,&c);
  if(a>b) //若成立,交换ab
{
  t=a;
  a=b;
  b=t;}
  if(a>c)//若成立,交换ac
 {
  t=a;
  a=c;
  c=t;}
  if(b>c) //若成立,交换bc
 {
 t=b;
 b=c;
 c=t;}
printf("输出结果:%d %d %d\n", a, b, c);
return 0;
}

题解二:

#include
#include
int main(){
printf("请输入三个整数");
int a,b,c,t,min,mid,max;
scanf("%d%d%d",&a,&b,&c);
    min = ((a<b)?a:b)<c?((a<b)?a:b):c;
    max = ((a>b)?a:b)>c?((a>b)?a:b):c;
    mid = a+b+c-min-max;
    printf("输出结果:%d %d %d",min,mid,max);
return 0;
} 

你可能感兴趣的:(c语言,程序设计)