Home » C Programs » Descending Order Program in C

Descending Order Program in C

Descending order program in c condition for beginners to sort the program in descending order which means the bigger values are the first values in the output

Descending Order in C and How it Works

Descending order is a numerical arrangement in which the largest number is placed first, followed by the smallest.

It refers to the practice of organizing numbers in ascending order from greatest to smallest. Descending means “down,” hence descending order indicates that the numbers are decreasing.

What does descending orders mean?

The ascending order is denoted by the sign, whereas the descending order is denoted by the > symbol

If Else Condition in C

If else is a conditional statement in programming that executes a separate series of statements based on whether an expression is true or false.

If a particular condition is true, the if/else statement executes a block of code. Another block of code can be performed if the condition is false.

Descending Order Program in C

//descending order program in c
#include<stdio.h>
void main()
{
int i,j,n,a[100],temp;
printf("Enter the elements\n");
scanf("%d",&n) ;
printf("Enter array elements\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("After descending order\n");
for(i=0;i<n;i++)
{
printf("%d ",a[i]);
}
}

Output:

Enter the elements

5

Enter array elements

34 65 1 78 65

After descending order

78 65 65 34 1