Thought Sharing

Friday, March 1, 2013

C++ program for sorting an array elements using bubble sort


#include
#include

void main()
{
int i,j,n,temp,a[100];
cout<<"enter size of array: ";
cin>>n;
cout<<"Enter elements of Array : ";
for(i=0;i{
cin>>a[i];
}
for(i=0;i{
for(j=i;j>=0;j--)
{
if(a[j]>a[j+1])
{
temp = a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"sorted elements of array are : ";
for(i=0;i{
cout<}
getch();
}