# Sort 10 Numbers

Source: Internet
Author: User

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

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.