//Selection Sort
//BCA Support
//www.bcasupport.xyz
#include <iostream.h>
#include <conio.h>
int num[10],temp,a,b,pos,min;
void small(int);
void sort();
void main()
{
clrscr();
cout<<"\nEnter 10 numbers :\n";
for(a=0;a<10;a++)
cin>>num[a];
sort();
cout<<"\nSorted array :\n";
for(a=0;a<10;a++)
cout<<num[a]<<endl;
getch();
}
void sort()
{
for(a=0;a<10;a++)
{
small(a);
temp=num[a];
num[a]=num[pos];
num[pos]=temp;
}
}
void small(int k)
{
min=num[k];
pos=k;
for(a=k;a<10;a++)
{
if(num[a]<min)
{
min=num[a];
pos=a;
}
}
a=k;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.