Choose the idea of sorting into the following:
There are 10 elements a[0]~a[10], compare a[1] and a[2]~a[10], if A[1] is smaller than a[2]~a[10, then no exchange, that is, no action. If one or more of the a[2]~a[10] is smaller than a[1], the largest of them (assuming A[i] and a[1] is exchanged, at which time A[1] holds the minimum number of 10. The 2nd round will a[2] and a[3]~a[10] Compare, will remain 9 number of the smallest person a[i] and a[2] swap, at this time a[2] is stored in 10 in the 2nd small book. And so on, a total of 9 rounds of comparison, A[1]~a[10] has been in the order of oil small to large storage)
The code is as follows:
#include <stdio.h>
int main ()
{
int i,j,min,temp,a[11];
printf ("Enter data:\n");
for (i=1;i<=10;i++)
{
printf ("a[%d]=", I);
scanf ("%d", &a[i]);
}
printf ("\ n");
printf ("The Origina numbers: \ n");
for (i=1;i<10;i++)
printf ("%5d", A[i]);
printf ("\ n");
for (i=1;i<=0;i++)
{
Min=i;
for (j=i+1;j<=10;j++)
if (A[min]>a[j])
min = j;
temp = A[i];
A[i] = temp;
A[min] = temp;
}
printf ("\nthe sorted numbers:\n");
for (i=1;i<=10;i++)
printf ("%5d", A[i]);
printf ("\ n");
return 0;
}
Sort 10 Numbers