输入
4
个整数,要求按从小到大的顺序输出。
解:程序:
#include<stdio.h>
int main()
{
int t,a,b,c,d;
printf(“请输入4个数:”);
scanf(“%d,%d,%d,%d”,&a,&b,&c,&d);
if (a > b)
{
t = a;
a = b;
b = t;
}
if (a > c)
{
t = a;
a = c;
c = t;
}
if (a > d)
{
t = a;
a = d;
d = t;
}
if (b > c)
{
t = b;
b = c;
c = t;
}
if (b > d)
{
t = b;
b = d;
d = t;
}
if (c > d)
{
t = c;
c = d;
d = t;
}
printf(“由小到大输出:%d %d %d %d\n”,a,b,c,d);
return 0;
}
结果:
请输入
4
个数:
2,5,3,0
由小到大输出
:0 2 3 5
请按任意键继续
. . .
本文出自 “
岩枭
” 博客,请务必保留此出处
http://yaoyaolx.blog.51cto.com/10732111/1741421