C Program to sort the entered elements using selection sort technique

CWC
0 Min Read

C Program to sort the entered elements using selection sort technique

#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( );
}

 

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version