Selection Sort
This is an example C of program which demonstrates a type of sorting of an array known as SELECTION SORT. We have provided input/output screenshots at the end of the code.
You can compile this program on bOtskOOl Free Online C/C++ Compiler
SOURCE CODE
//SELECTION SORT
/*
**********************
www.botskool.com
**********************
*/
#include <iostream>
using namespace std;
int main()
{
int i,j,loc,low,ar[5],temp;
for(i=0;i<5;i++)
{
printf("\nEnter the no. %d element ",i);
scanf("%d",&ar[i]);
}
for(i=0;i<5;i++)
{
low=ar[i];
loc=i;
for(j=i+1;j<5;j++)
{
if(ar[j]<low)
{
low=ar[j];
loc=j;
}
}
temp=ar[loc];
ar[loc]=ar[i];
ar[i]=temp;
}
printf("\nThe elements in Ascending Order are \n");
for(j=0;j<5;j++)
printf("%d ",ar[j]);
}

The above OUTPUT was generated by bOtskOOl Online Compiler try>>
>>Kindly post your doubts and suggestions on our discussion forum.




Recent comments
11 weeks 10 hours ago
1 year 8 weeks ago
1 year 11 weeks ago
1 year 11 weeks ago
1 year 12 weeks ago
1 year 13 weeks ago
1 year 14 weeks ago
1 year 14 weeks ago
1 year 18 weeks ago
1 year 18 weeks ago