Skip to main content

Program for Selection Sort in CPP

· One min read
Kaustubh Kulkarni
Selection.cpp
  
#include

using namespace std;

int main()
{
int i,j,n,loc,temp,min;
cout<<"Enter the number of elements:";
cin>>n;
cout<<"nEnter the elementsn";
int a[n];
for(i=0;i {
cin>>a[i];
}

for(i=0;i {
min=a[i];
loc=i;
for(j=i+1;j {
if(min>a[j])
{
min=a[j];
loc=j;
}
}

temp=a[i];
a[i]=a[loc];
a[loc]=temp;
}

cout<<"nSorted list is as followsn";
for(i=0;i {
cout< }

return 0;
}