C program for sort the elements of an array in descending order

				
					#include<stdio.h> 
#include<conio.h> 
void main() 
{ 
int *ar, temp, i, j, n; 
clrscr(); 
printf(“enter the number of elements in the array”); 
scanf(“%d”, &n); 
ar=(int*)malloc(sizeof(int)*n); 
for(i=0;i<n;i++) 
{ 
for(j=i+1; j<n; j++) 
{ 
if(ar[i]<ar[j]) 
{ 
temp=ar[i]; 
ar[i]=ar[j]; 
ar[j]=temp; 
} 
} 
printf(“Elements of array in descending order are”); 
for(i=0; i<n; i++) 
printf("%d",*a); 
getch(); 
}
				
			
Output: Enter the number of elements in the array: 5 
Enter a number: 32
Enter a number: 43 
Enter a number: 23 
Enter a number: 57 
Enter a number: 47Elements of array in descending order are:
57 
47 
43 
32
 23

Leave a Reply