Sorting an array selection method

#include <stdio.h>

int main ()

{

  int n;

  int a[10],i,j,k;

  scanf("%d",&n);

  for (i=0;i<n;i++)

  scanf ( "% d", & a [i]); // number of input n

 

  for (k=0;k< n;k++)

 {

    j = k; // j parameter determines the size of the increase

    for (i=k+1;i<n;i++)

   {

      if (a[i]>a[j])

      j = i; // record the maximum number of index positions

    }

 

    if (j!=i)

    {

       temp=a[i];

       a[i]=a[k];

       a[k]=a[i];

    }

    for (k=0;k<n;k++)

   {

       printf("%d ",a[k]);

   }

}

      

 

   

Guess you like

Origin www.cnblogs.com/DEAKY/p/11872770.html