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
You must be logged in to post a comment.