F Selection Sort Using C | CodeTheta

Selection Sort Using C

December 20, 2015

Here is a program of selection sort which is written in C programming. This program uses array to sort the elements.

/* http://native-code.blogspot.com */
#include<stdio.h>
#include<conio.h>
void main()
      {
    int a[10],i,j,n,MIN,loc,TEMP;
    clrscr();
    printf("/* http://native-code.blogspot.com */");
    printf("\n\n How Many Numbers Do You Want To Enter?");
    scanf("%d",&n);
    printf("\n\n Enter The Numbers.\n");
       for(i=0;i<n;i++)
         {
        printf("\n A[%d] = ",i+1);
        scanf("%d",&a[i]);
          }
    printf("/* http://native-code.blogspot.com */");
    printf("\n\n You Have Entered The Numbers ");
    for(i=0;i<n;i++)
      printf(" %d",a[i]);
for(i=0;i<n-1;i++)
   {
    MIN=a[i];
    loc=i;
    for(j=i+1;j<n;j++)
     {
    if(MIN>a[j])
      {
        MIN=a[j];
        loc=j;
      }
     }
    TEMP=a[i];
    a[i]=a[loc];
    a[loc]=TEMP;
    }
    printf("/* http://native-code.blogspot.com */");
    printf("\n\n Now Sorted List Is");
       for(i=0;i<n;i++)
       printf(" %d",a[i]);
    getch();
  }
/* http://native-code.blogspot.com */

IDE Used To Test This Code : Turbo C

Try this code in your computer for better understanding. Enjoy the code. If you have any Question you can contact us or mail us.

Post a Comment