u

Wednesday 6 June 2012

C++ Program to conduct: Array sorting Using Insertion Sorting Technique

C++ Program to conduct: Array sorting Using Insertion Sorting Technique.
Program to input any five numbers and print them in descending order


#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int number[5],j=0,a=0;
clrscr(); // clear the screen
cout<<"Enter the elements of the array"<<endl;
for(int i=1;i<=5;i++)
{
cout<<"Enter number "<<endl;
cin>>number[i];
}
cout<<"The original list is ";
for(i=1;i<=5;i++)
{
cout<<number[i]<<"\t";
}
cout<<endl;
cout<<endl<<"Thank You ! The data entry is over"<<endl;
cout<<"Press any key to continue";
getch();
cout<<"\a\a";
// sorting of data
for(int k=2;k<=5;k++)
{
a=number[k];
j=k-1;
while(a<number[j] && j>0)
{
  number[j+1]=number[j];
  j=j-1;
}
number[j+1]=a;
}
cout<<endl;
cout<<"The list in ascending order is ";
cout<<endl;
for(i=1;i<=5;i++)
cout<<number[i]<<"\t";
cout<<endl<<"Press any key to return to the editor";
getch();
return 0;
}

0 comments:

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More