Praveen | Typing Speed Test is a very useful Software available for free Download.

C Programs to Selection Sort

      Selection sorting to sort numbers, And arrange them in ascending order or descending order. Selection sorting in ascending order means one element to check any other elements of sequentially, if selected number is greater then to exchange positions of numbers, Otherwise continue to perform the specific operations.


Selection sorting in Ascending order C programming code

#include<stdio.h>
#include<conio.h>


void main()
{
   int a[100], n, i, j, temp;
   clrscr();
   printf("\n Enter number of elements ");
   scanf("%d", &n);
   printf("\n Enter %d integer numbers ", n);
   for ( i = 0 ; i < n ; i++ )
      scanf("%d", &a[i]);
   for ( i = 0 ; i < ( n - 1 ) ; i++ )
   {
      for ( j = 0 ; j < ( n - i - 1 ) ; j++ )
      {
          if ( a[i] < a[j] )
          {
             temp = a[j];
             a[j] = a[j+1];
             a[j+1] = temp;
          }
      }
   }
   printf("\n Sorted list in ascending order:-");
   for ( i = 0 ; i < n ; i++ )
       printf(" %d,", a[i]);

   getch();
}


 Output:-
                    







No comments:

Post a Comment