Selection sort(output incorrect and repeats some values)

closed account (1vf9z8AR)
#include<iostream>
using namespace std;
int selection_sort(int a[10],int n)
{
int i,j,k,temp,least;
for(i=0;i<n-1;i++)
{
cout<<"At "<<i+1<<" pass"<<endl;
least=a[i];
for(j=i;j<n-1;j++)
{
if(a[j]<least)
{
temp=a[j];
a[j]=least;
least=temp;
}
}
}
for(k=0;k<n;k++)
cout<<a[k]<<endl;
}
int main()
{
int n,i,a[10];
cout<<"Enter number of elements:";cin>>n;
cout<<"\nEnter elements"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
cout<<"Ascending order-"<<endl;
selection_sort(a,n);
}
int selection_sort(int a[10],int n)
return statement missing for this function that is expected to return an int
Topic archived. No new replies allowed.