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

Archives

program to sort the array using function

Tuesday, September 1, 2009

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
 int x[10],n;
 cout<<"enter number of elements:";
 cin>>n;
 void sort(int x[],int);
 cout<<"enter the elements:";
 for(int i=0;i<n;i++)
  cin>>x[i];
  sort(x,n);
  cout<<"elements after sorted become:";
  for(int j=0;j<n;j++)
  cout<<x[j]<<'\t';
  getch();
  }
  void sort(int x[],int a)
  {
   for(int i=0;i<a-1;i++)
    {
     for(int j=i+1;j<a;j++)
      {
    if(x[i]>x[j])
    { int m;
     m=x[j];
     x[j]=x[i];
     x[i]=m;
     }
       }
     }
    }

0 comments: