Name: Number Sequence
Description of the Program: This program displays the input numbers in descending order.
Description of the Program: This program displays the input numbers in descending order.
As you can see in the screenshot below, I entered 5 numbers. The numbers are 98,34,56,9 and 5. Then, it displayed the five numbers, 98-56-34-9-5 in descending order.
//Below are the Codes of the Program:
#include<iostream.h>
#include<conio.h>
void swap (int& a, int& b)
{
int c,d;
c=a;
d=b;
a=d;
b=c;
}
int main()
{
int c,a[90]={0},b[90]={0},d,i;
cout<<"How many numbers? ";
cin>>c;
for(int d=0;d<c;d++)
{
cout<<"\n";
cout<<(d+1)<<" input: ";
cin>>a[d];
}
for(int g=0;g<c;g++)
{
for(int e=0;e<c;e++)
{
if((e+1)<c)
{
if (a[e]<a[e+1])
swap(a[e],a[e+1]);
}
}
}
for(int f=0;f<c;f++)
{
cout<<a[f]<<"\t";
}
getch();
}
#include<conio.h>
void swap (int& a, int& b)
{
int c,d;
c=a;
d=b;
a=d;
b=c;
}
int main()
{
int c,a[90]={0},b[90]={0},d,i;
cout<<"How many numbers? ";
cin>>c;
for(int d=0;d<c;d++)
{
cout<<"\n";
cout<<(d+1)<<" input: ";
cin>>a[d];
}
for(int g=0;g<c;g++)
{
for(int e=0;e<c;e++)
{
if((e+1)<c)
{
if (a[e]<a[e+1])
swap(a[e],a[e+1]);
}
}
}
for(int f=0;f<c;f++)
{
cout<<a[f]<<"\t";
}
getch();
}