03 June, 2013

C++ Program To Perform Bubble Sort In Descending Order.

This Post Contains A C++ Program To Perform Bubble Sort In Descending Order. With Correct Source Code & Output. This Program Is Written, Compiled & Executed At TurboC/C++3.0 Compiler & Will Help You To Understand The Concept Of 'Bubble Sort' From C++ Language. It Is A Well-Structured Program With Proper Comments Which Provides Step-By-Step Description Of Various Features Of The Language
In A Simple & Easy-To-Understand Way.


# Note : You Can Simply Copy-Paste The Following Program Or Code Into Compiler For Direct Result.



C++ Program To Perform Bubble Sort In Descending Order.


/* Declaration Of Header Files */
#include<iostream.h>
#include<conio.h>

/* Start Of Main Program */
void main()
{
int i, j, dim=0, temp=0;
int a[20];
clrscr();

// Accepting Range Of Array From User.
cout<<" \n Enter Dimension : ";
cin>>dim;

// Accepting Values Of Array From User.
cout<<" \n Enter Values For Array : ";
for(i=0;i<dim;i++)
{
cin>>a[i];
}

// Printing Values Of Array.
for(i=0;i<dim;i++)
{
cout<<a[i]<<"\t";
}

// Sorting Values In Descending Order.
for(i=1;i<=dim;i++)
{
  for(j=1; j<=(dim-i); j++)
  {
    if(a[j]<a[j+1])
    {
       temp=a[j];
       a[j]=a[j+1];
       a[j+1]=temp;
    }
  }
}

// Printing Values Of Array 'a' After Sorting.
cout<<" \n Sorted Array Is : ";
for(i=1;i<=dim;i++)
{
cout<<a[i]<<"\t";
}
getch();
}
/* End Of Main Program */

 
Output :

Enter Dimension : 5

Enter 5 Values :
44  22  11  55  33

Sorted Array Is :
55  44  33  22  11




No comments:

Post a Comment

Subscribe To:

Most Commonly Asked Programs In 'C' & 'C++' Language.

Blog Archive