C Program To Sort Array in Descending Order
Learn How To Sort Array in Descending Order in C Programming. It is important that we should know How A For Loop Works before getting further with the C Program Code. This Array Sorting C Program is executed on a 1 – Dimensional Array. The Code For Sorting Arrays in Descending Order method is executed using For Loops.
Also Read: Replace A Character in a String in C Programming
C Program To Sort Array in Descending Order using For Loop
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<stdio.h> int main() { int arr[50], temp; int limit, i, j; printf("\nEnter the size of the array: \t"); scanf("%d", &limit); for(i = 0; i < limit; i++) { printf("Enter Element %d:\t", i + 1); scanf("%d", &arr[i]); } printf("\nArray\n"); for(i = 0; i < limit; i++) { printf("%d\t", arr[i]); } for(i = 0; i < limit; i++) { for(j = 0; j < limit - 1; j++) { if(arr[i] > arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } printf("\nSorted Array\n"); for(i = 0; i < limit; i++) { printf("%d\t", arr[i]); } printf("\n"); return 0; } |
Also Read: C Program To Check Validity of a Triangle
Output

If you have any compilation errors or doubts in this Sort Array Elements in Descending Order, let us know about it in the Comment Section below.