#include
main()
{
int i,j,temp;
int a[4];
printf("Please you input the four number you want to campare!\n");
for(i=0;i<4;i++) /*输入要比较的四个数字*/
scanf ("%d,",&a[i]);
for(j=0;j<4;j++)/*采用冒泡排序法排序*/
{
for (i=0;i<4-j;i++)
if (a[i]>a[i+1])
{ temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;}
}
/*输出排序结果*/
printf("the number list from min to max is:");
for(i=0;i<4;i++)
printf("%d ",a[i] );
}
此程序在vc++中编译运行成功,基本思想是运用冒泡排序法进行排序!
找书上 用 冒泡排序法 就OK了
#include
#define sizeArr 4
void bubblesort(int a[]){
int judge=0;
int cir=sizeArr-1;
int flag;
while (cir)
{
while (judge!=cir)
{
flag=a[judge]-a[judge+1];
switch ((flag>=0))
{
case 1:
int temp;
temp=a[judge];a[judge]=a[judge+1];a[judge+1]=temp;
}
judge++;
}
judge=0;
cir--;
}
}
void main(){
int a[sizeArr];
for (int i=0;i
scanf("%d",&a[i]);
}
bubblesort(a);
for (int j=0;j
printf("%d\t",a[j]);
}
}