C Program to Sort the Array in Descending Order

In this program, you will take input from the user and sort the array in descending order. for example, given arrays are 5,2,3,1,6. after sorting array become 6,5,3,2,1

Program to Sort the Array in Descending Order

#include<stdio.h>
int main()
{
 int a[50],i,j,temp,n;
 printf("\nenter size of array:");
 scanf("%d",&n);
 printf("enter element in array:");
 for(i=0;i<5;i++)
 {
   scanf("%d",&a[i]);
  }
 for(i=0;i<5;i++)
 {
   for(j=i+1;j<5;j++)
   {
     if(a[j]>a[i])
     {
        temp=a[j];
        a[j]=a[i];
	a[i]=temp;
     }
    }
  }
  printf("array in decending order are: ");
  for(i=0;i<5;i++)
  {
     printf("%d\t",a[i]);
   }
}

output

enter size of array:5
enter element in array:3 1 4 2 5
array in decending order are: 5     4       3       2       1