Sunday, September 15, 2019

C++ Language Program for Sort Any Array in Descending Order.

BACHELOR OF COMPUTER APPLICATION (B.C.A.) FIRST SEMESTER

Here you will get simple C++ program 
C++ Language Program Sort Any Array in Descending Order.
IT IS THE SMALLEST LOGIC USED FOR CODING OF THIS PROGRAM.
IN WHICH YOU CAN CREATE OWN VARIABLES AND FUNCTIONS.

User will input will be an unsorted form in Array and that Array is sorted by Descending Order,then it will be display on screen.


The program coding is given below.
#include<iostream.h>
#include<conio.h>
class Sort
{
int a[20],i,j,temp;
public:
void getdata()
{
cout<<"Enter elements of array:\n";
for(i=1;i<=5;i++)
cin>>a[i];
}
void sort()
{
temp=0;
for(i=1;i<=5;i++)
{
    for(j=1;j<=5;j++)
    {
       if(a[i]>a[j])
       {
temp=a[i];
a[i]=a[j];
a[j]=temp;
       }
    }
}
}
void display()
{
cout<<"Array after sorting:\n";
for(i=1;i<=5;i++)
{
cout<<" "<<a[i];
}
}
};
void main()
{
clrscr();
Sort s1;
s1.getdata();
s1.sort();
s1.display();
getch();
}
Output will be given after you compile it.

No comments:

Post a Comment