C Program To Sort Array Elements In Descending Order Using Bubble Sort

C program to sort array elements in descending order using bubble sort.

Write a C program to sort array elements in descending order using bubble sort. C Program :
/* Aim: C Program to sort integers of an array in descending order using bubble sort method */

#include<stdio.h>

void main()
{
	int arr[50],i,size,temp,j;
 
	printf("\n How many numbers to accept:- ");
	scanf("%d",&size);
 
	printf("\n Enter the array elements:- ");
	for(i=0;i<size;i++)
	scanf("%d",&arr[i]); 
  
	for(i=1;i<size;i++)
	{
		for(j=0;j<size-i;j++)
		{
			if(arr[j]<arr[j+1])
			{
			temp=arr[j];
			arr[j]=arr[j+1];
			arr[j+1]=temp;
			} 
		}
	} 

	printf("\n The array elements in descending order:- ");
	for(i=0;i<size;i++)
		printf(" %d",arr[i]);
 
	printf("\n \n");
}
 

/* Output of above code:- 

[root@localhost ~]# cc Bubble_Sort_DESC.c
[root@localhost ~]# ./a.out

 How many numbers to accept:- 5

 Enter the array elements:- 12 10 50 40 13

 The array elements in descending order:-  50 40 13 12 10

*/