📊⚡Beginner
Sort Array in Descending Order
Sort from high to low
Sort array in descending order (largest to smallest).
Program Code
sort_descending.c
C
1#include <stdio.h>23int main() {4 int arr[] = {64, 34, 25, 12, 22, 11, 90};5 int n = sizeof(arr) / sizeof(arr[0]);6 7 // Selection Sort - Descending8 for (int i = 0; i < n - 1; i++) {9 int maxIdx = i;10 for (int j = i + 1; j < n; j++) {11 if (arr[j] > arr[maxIdx]) {12 maxIdx = j;13 }14 }15 // Swap16 int temp = arr[maxIdx];17 arr[maxIdx] = arr[i];18 arr[i] = temp;19 }20 21 printf("Sorted (descending): ");22 for (int i = 0; i < n; i++) {23 printf("%d ", arr[i]);24 }25 printf("\n");26 27 return 0;28}Output
Sorted (descending): 90 64 34 25 22 12 11
Related Examples
Want to Learn More?
Explore our comprehensive tutorials for in-depth explanations of C programming concepts.
Browse Tutorials