Saturday, March 15, 2014

Ascending Sorting of Array



This Program will help you to sort an array using bubble sorting technique.                                                                                                                                                                                                                                                                                                                                               
#include<iostream.h>
#include<conio.h>
void main()
{
int a[10],b;
cout<<"Enter the array: "<<endl;
 for (int i=0;i<10;i++)
  cin>>a[i];                       //this will populate the array
 for (int i=0;i<10;i++)
 {
  for (int k=i+1;k<10;k++)
  {
   if (a[i]>a[k])
    {
     b=a[k];
     a[k]=a[i];                    //this will compare each element of array with rest
     a[i]=b;
    }
  }
 }
cout<<endl<<"Sorted array is:   ";
for (int i=0;i<10;i++)
 cout<<a[i]<<" ";                          //this will display the array
getch();
}

Widgets

 

Copyright @ 2014 CPP Fuzz.