Home > Back-end >  Selection sort
Selection sort

Time:12-24

#include

Int main ()

{

Int I, j, t, a, [11].

Printf (" please enter the number 10: \ n ");

for(i=1; i<11. I++)

The scanf (" % d ", & amp; A [I]);//input from the keyboard to sort of 10 Numbers

for(i=1; i<=9; I++)

For (j=I + 1; J<=10; J++)

If (a [I] & gt; Before a [j])//if a number is larger than a number after, swap with intermediate variable t realize two values

{

t=a[i];

a[i]=a[j];

A [j]=t;

}

Printf (" sorted order is: \ n ");

for(i=1; i<=10; I++)

Printf (" % 5 d, "a [I]);//output sorted array

printf("\n");

return 0;

}
% 5 d has four Spaces between each number
  • Related