You are on page 1of 1

//Selection Sort #include<iostream.h> #include<conio.h> void main() { clrscr( ); int a[50],item,n,pos,temp; cout<<"Enter th no.

of elements in list\n"; cin>>n; cout<<"\nEnter array elements\n"; for(int i=0;i<n;++i) { cin>>a[i];} for(i=0;i<n;i++) { small=a[i]; for(int j=i+1;j<size;j++) { if(a[j]<small) {small=a[j];pos=j;} } temp=a[i]; a[i]=a[pos]; a[pos]=temp; } cout<<"The sorted array is as shown below:-\n"; for(i=0;i<n;i++) {cout<<a[i]<<" ";} getch(); } Output:Enter th no. of elements in list 5 Enter array elements 56 78 45 65 32 The sorted array is as shown below:32 45 56 65 78

You might also like