Write a program in C to sort array elements in descending order.
#include<stdio.h> #include<conio.h> void main() { int temp,i,n,j,a[30]; clrscr(); printf("How many number you want enter in an array.:-"); scanf("%d",&n); printf("Enter %d nos.:-",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("Sort of arranged in descending order="); for(i=0;i<n;i++) printf("%4d",a[i]); getch(); }
Output:-
Related programs:
- Write a program in C to sort array elements in ascending order.
- Write a program in C to check that a number entered by the user is Armstrong number.
- Write a program to print 1 to 100 numbers using while loop.
- Write a program in C to find greatest prime number less than a given positive number.
0 Comments