冒泡法是好,不过要不用数组的
其实只要能想出输出最大和最小两个的办法!就有办法自己想出四个排列的,最多复杂一点.
建议你调用子函数,利用冒泡法的思路
com(int a,int b)
{//这是比较的子函数
int c;
if(a>b)
{c=a;
a=b;
b=c;
}
}
然后你就只要联系三次调用就可以了
也就是每两个都按从大到小排列,整个就是重大到小
PROGRAM 程序名(input,output);
Var a,b,c,d,t: Real;
Begin
Write('Input a, b,c=');
Readln(a,b,c,d);
if a>b then
begin {复合语句}
t:=a; a:=b; b:=t {交换a,b}
end;
if a>c then
begin {复合语句}
t:=a; a:=c; c:=t {交换a,c}
end;
if a>d then
begin {复合语句}
t:=a; a:=d; d:=t {交换a,d}
end;
if b>c then
begin {复合语句}
t:=b; b:=c; c:=t {交换b,c}
end;
if b>d then
begin {复合语句}
t:=b; b:=d; d:=t {交换b,d}
end;
if c>d then
begin {复合语句}
t:=c; c:=d; d:=t {交换d,c}
end;
Writeln('a,b,c,d:',a:6, b:6, c:6, d:6);
Readln
End.
参考算法自己编一个C语言的吧,很容易的^_^
#include "stdio.h"
main()
{
int i,j,t,a[4];
printf("please input 4 numbers\n");
for(i=0;i<=3;i++)
scanf("%d",&a[i]);
for(i=0;i<=2;i++)
for(j=i+1;j<=3;j++)
if(a[i] {
t=a[i];
a[i]=a[j];
a[j]=t;
}
for(i=0;i<=3;i++)
printf("%d\t",a[i]);
}
是标准算法也是最烂的算法,快速排序是共认目前最好的
同意楼上的冒泡排序法
这是标准算法