Posts

Showing posts with the label selction sort programm in cpp

selction sort programm in cpp

#include<iostream> using namespace std; int main() {     int i,j,n,temp,a[30];     cout<<"Enter the number of elements:";     cin>>n;     cout<<"\nEnter the elements\n";     for(i=0;i<n;i++)     {         cin>>a[i];     }     for(i=0;i<n-1;i++)     {         for(j=i+1;j<n;j++)         {             if(a[i]>a[j])             {                 temp=a[j];                 a[j]=a[i];                 a[i]=temp;             }         }     }     cout<<"\nSorted list is as follows\n";     for(i=0;i<n;i++)     {         cout<<a[i]<<" ";     }     return 0; }