0% found this document useful (0 votes)
61 views2 pages

Arranging An Array in Descending Order

The document contains C++ code to rearrange an array of numbers in descending order. It first prompts the user to enter the size of the array and its elements. It then uses a double for loop to compare all elements and swap any that are out of order, with the larger number appearing first in the sorted array. Finally, it prints out the rearranged array of numbers from largest to smallest.

Uploaded by

Madhuri Ganguly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views2 pages

Arranging An Array in Descending Order

The document contains C++ code to rearrange an array of numbers in descending order. It first prompts the user to enter the size of the array and its elements. It then uses a double for loop to compare all elements and swap any that are out of order, with the larger number appearing first in the sorted array. Finally, it prints out the rearranged array of numbers from largest to smallest.

Uploaded by

Madhuri Ganguly
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

DATE: 3.9.

12

ROLL NO.: 1653

/*Aim: TO REARRANGE A LIST OF NUMBERS IN DECSENDING


ORDER.*/
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int arr[50],n,i,j,temp;
cout<<"\n\n\t\tPROGRAM TO SORT ARRAY IN DESCENDING ORDER";
cout<<"\n_______________________________________________________________
_________________\n";
cout<<"\nEnter size of array:\t";
cin>>n;
cout<<"\nEnter array elements:\t";
for(i=0;i<n;i++)
{
cin>>arr[i];
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(arr[j]>arr[i])
{
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
cout<<"\n\nThe sorted array in DESCENDING order:\n\n";
cout<<"\t\t\t";
for(i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
getch();
}

RESULT:

You might also like