0% found this document useful (1 vote)
8K views1 page

C++ Program For Sorting Numbers in Descending Order

The document describes a C++ program to sort an array of numbers in descending order. The program takes user input for the number of elements and values to populate an array. It then uses a double for loop with an if statement to compare adjacent elements and swap them if out of order, sorting the array in descending order. Finally, it outputs the sorted array.

Uploaded by

jokerbuddy01
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
8K views1 page

C++ Program For Sorting Numbers in Descending Order

The document describes a C++ program to sort an array of numbers in descending order. The program takes user input for the number of elements and values to populate an array. It then uses a double for loop with an if statement to compare adjacent elements and swap them if out of order, sorting the array in descending order. Finally, it outputs the sorted array.

Uploaded by

jokerbuddy01
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a C++ program to sort given numbers in descending order. #include<iostream.h> #include<conio.h> #include<math.

h> void main() { int a[20],i,j,temp,n; clrscr(); cout<<"enter number of elements"<<endl; cin>>n; cout<<"enter the elements one by one"<<endl; for(i=0;i<n;i++) cin>>a[i]; for(i=0;i<n;i++) { for(j=0;j<n-1-i;j++) { if(a[j]<a[j+1]) { temp=a[j]; a[j]=a[j+1]; a[j+1]=temp; } } } cout<<"the sorted array in ascending order is"; for(i=0;i<n;i++) cout<<endl<<a[i]; getch(); }

You might also like