Q:

C Program For Selection Sort In Ascending And Descending order

belongs to collection: Sorting C Programs

0

Selection Sort is the most simplest Sorting Technique, in this sorting technique first finds the smallest or largest element (depending on the order that you want to do) and swaps the smallest or largest elements with the corresponding element.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include
int main()
{
  int s,i,j,temp,a[20];

  printf("Enter total elements: ");
  scanf("%d",&s);

  printf("Enter %d elements: ",s);
  for(i=0;i      scanf("%d",&a[i]);

  for(i=0;i      for(j=i+1;j           if(a[i]>a[j]){
               temp=a[i];
              a[i]=a[j];
              a[j]=temp;
           }
      }
  }

  printf("After sorting is: ");
  for(i=0;i      printf(" %d",a[i]);

  return 0;
}

 

Output:

Enter total elements: 5

Enter 5 elements: 12

45

-56

0

151

After sorting is :-56 0 12 45 151

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C Program For Insertion Sort In Ascending Order... >>
<< C Program For Bubble Sort In Ascending And Descend...