C语言题 输入三个数,分别按照从小到大和从大到小的的顺序输出

要用到else if什么的

而且是从小到大和从大到小是一起输出,是一个程序里的。

希望高手给的答案简单点,我是初学者,谢谢。

  #include <stdio.h>
  int main()
  {
  int t,a,b,c;
  scanf("%d%d%d",&a,&b,&c);
  if(a<b)
  {
  t=a,a=b,b=t;
  }
  if(a<c)
  {
  t=a,a=c,c=t;
  }
  if(b<c)
  {
  t=b, b=c, c=t;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
  }
  原理就是运用冒泡算法,把最大的数浮在最上面,而小的数就下沉,最后就输出。
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-25
#include<stdio.h>
void main()
{
int a,b,c,temp;
printf("输入三个数");
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",a,b,c);
printf("由小到大输出%d%d%d",c,b,a);
}本回答被提问者采纳
第2个回答  2012-02-28
#include<stdio.h>
void swap(int &a,int &b) // 该函数用于改变两个数字的大小位置
{
int temp = 0;
temp = a;
a = b;
b = temp;
}
void main()
{
int a=10,b=5,c=20;
if (a>b)
swap(a,b); //交换之后a<b了
if (c>b)
printf("%d,%d,%d\n",a,b,c);
else if (c>a) //c在a和b之间
printf("%d,%d,%d\n",a,c,b);
else //c最小
printf("%d,%d,%d\n",c,a,b);
}
第3个回答  2012-02-28
有很多办法,但是你具体要说明需要输入哪三个数。
#include<stdio.h>
main()
{
int a;
scanf("%d",&a);
if (a)
printf("123")
else
{
printf("321")
}
}
第4个回答  2012-02-28
输入a,b,c,d如果a大于b则将a赋予d,将b值赋予a,循环一下就行了
相似回答