#include<iostream.h>
#include<conio.h>
void SelectionSort(int a[],int n)
{
int min,pos,i,j;
for(i=0;i<=n-1;i++)
{
min=a[i];
pos=i;
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
pos=j;
}
}
int temp;
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
}
void main()
{
clrscr();
int a[50],i,n,d,pos;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
SelectionSort(a,n);
cout<<"Ascending Order";
for(i=0;i<n;i++)
{
cout<<a[i]<<",";
}
getch();
}
#include<conio.h>
void SelectionSort(int a[],int n)
{
int min,pos,i,j;
for(i=0;i<=n-1;i++)
{
min=a[i];
pos=i;
for(j=i+1;j<n;j++)
{
if(a[j]<min)
{
min=a[j];
pos=j;
}
}
int temp;
temp=a[i];
a[i]=a[pos];
a[pos]=temp;
}
}
void main()
{
clrscr();
int a[50],i,n,d,pos;
cout<<"Enter the number of elements ";
cin>>n;
cout<<"Enter the elements";
for(i=0;i<n;i++)
{
cin>>a[i];
}
SelectionSort(a,n);
cout<<"Ascending Order";
for(i=0;i<n;i++)
{
cout<<a[i]<<",";
}
getch();
}