Programming Ideas

Freind’s let’s learn how  to sort the elements of an array.See how to arrange  elements of an array in systematic manner.In this program i have written the ways how to sort elements of an array.

Written By: Vivek Sharma

#include<iostream>
#include<conio.h>
#include"swap.h"
using namespace std;

int main()
{
    int a[10],h,t,i;

    cout<<"Enter 10 numbers: ";

    for(i=0;i<10;i++)
    {
        cout<<endl<<i+1<<":";
        cin>>a[i];
    }
    cout<<"\nUnsorted Array \n ";
    for(i=0;i<10;i++)
    {

        cout<<a[i]<<" ";
    }
    h=0;
    t=h+1;
    for(i=0;i<10;i++)
    {
       if(t<10)
       { 
          if(a[h]>a[t])
          {
             swap(a[h],a[t]);
          }

          t++;
       }
       else
       {
           if(h==t-1)
           {
              break;
           }
           else
           {

               h++;
               i=0;
               t=h+1;
           }
       }
    }
    cout<<"\n Sorted Array\n ";
    for(i=0;i<10;i++)
    {
        cout<<a[i]<<" ";
    }
    getch();
    return 0;
}

Leave a Reply

Link Exchange
Advertisement
Get one year License for Avast FREE ! Go to Avast Official Site to download and get the License
About Me
I am a Master of Computer Application (MCA) degree holder. I am also qualified UGC-NET Lecturership in Computer Science & Application.

I am available for Freelancing.

Expert in :
  1. C# Programming (Desktop & Web)
  2. VB.NET Programming (Desktop & Web)
  3. PHP Web Designing + CSS3
  4. SQL Administration
  5. Ethical Hacking
Site Estimated Cost
zosoftnet.com website worth badge