<br />#include<iostream> #include<conio.h> using namespace std; int smallest(int a[],int k,int n) { int pos=k,small=a[k],i; for(i=k+1;i<n;i++) { if(a[i]<small) { small=a[i]; pos=i; } } return pos; } void selection_sort(int a[],int n) { int k,pos,temp; for(k=0;k<n;k++) { pos=smallest(a,k,n); temp=a[k]; a[k]=a[pos]; a[pos]=temp; } } int main() { int a[10],n,i,j,k; cout<<"Enter the size of the array:"<<endl; cin>>n; cout<<"Enter the elements:-"<<endl; for(i=0;i<n;i++) { cin>>a[i]; } selection_sort(a,n); cout<<"The Sorted array is:-"<<endl; for(i=0;i<n;i++) { cout<<a[i]<<" "; } cout<<endl; cout<<endl<<"Thanks...@Myprogworld..!!"<<endl; getch(); return 0; }
corollary:-