Program to sort the entered elements using selection sort technique - 100 Most Important C# Programs

100 Most Important C# Programs

73. Program to sort the entered elements using selection sort technique.

Code:

#include<stdio.h>

#include<conio.h>

main( )

{

int a[100],i,n,j,t,min,pos;

clrscr();

printf(“enter the array size”);

scanf(“%d”,&n);

printf(“enter the elements”);

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

scanf(“%d”,&a[i]);

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

{

min=a[i];

pos=i;

for(j=0;j<n-1;j++)

if(min>a[j])

{

min=j;

pos=j;

}

t=a[i];

a[i]=a[pos];

a[pos]=t;

}

printf(“the sorted elements are”);

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

printf(“%2d”,a[i]);

getch( );

}