#include<stdio.h>
void sorted(int array[],int n);
int main()
{
int i;
int b[4];
printf("please enter four numbers:\n" );
for(i=0;i<4;i++)
scanf("%d",&b[i]);
printf("\n");
for(i=0;i<4;i++)
printf("%d ",b[i]);
printf("\n");
sorted(b,4);
printf("The sorted is:\n");
for(i=0;i<4;i++)
printf("%d ",b[i]);
printf("\n");
return 0;
}
void sorted(int array[],int n)
{
int i,j,t,k;
for(i=0;i<n-1;i++)
{k=i;
for(j=i+1;j<n;j++)
if(array[j]>array[k])
k=j;
t=array[k];array[k]=array[i];array[i]=t;
}
}
please enter four numbers:
10 20 -100 0
10 20 -100 0
The sorted is:
20 10 0 -100
--------------------------------
Process exited with return value 0
Press any key to continue . . .