Thursday, 7 December 2017

PROGRAM SELECTION SORT

"Nice One Program"


#include<iostream.h>
#include<conio.h>

void main()
{       clrscr();
 int *a,i,n,j,temp;
cout<<"Enter numbr of elements:";
cin>>n;
a=new int[n];
cout<<"enter elemnts:";
for(i=0;i<n;i++)
cin>>a[i];

cout<<"\n\nelements Before sorting:";
for(i=0;i<n;i++)
cout<<a[i]<<" ";

for(i=0;i<n-1;i++)
for(j=i+1;j<n;j++)
if(a[i]>a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;

}


cout<<"\n\nElemnts aftr selction sortng:";
for(i=0;i<n;i++)
cout<<a[i]<<" ";


getch();

}








No comments:

Post a Comment