My photo
Bangalore, Karnataka, India
Extending one hand to help someone has more value rather than joining two hands for prayer

Archives

program of selection sort

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int a[100],smal,n,temp;
 cout<<"enter the number of elements: ";
 cin>>n;
 cout<<"enter the elements: "<<endl;
 for(int i=0;i<n;i++)
 cin>>a[i];
 for(i=0;i<n;i++)
 {
  smal=a[i];
   for(int j=i+1;j<n;j++)
    {
     if(smal>a[j])
      {
    temp=smal;
    smal=a[j];
    a[j]=temp;
       }
     }
  a[i]=smal;
  }
  cout<<"elements after selection sort"<<endl;
  for(i=0;i<n;i++)
  cout<<a[i]<<" ";
  getch();
  }

0 comments: