fork download
  1. #include <stdio.h>
  2.  
  3. void sortArray(int arr[], int n) {
  4. for (int i = 0; i < n; i++) {
  5. for (int j = i + 1; j < n; j++) {
  6. if (arr[i] < arr[j]) {
  7. int temp = arr[i];
  8. arr[i] = arr[j];
  9. arr[j] = temp;
  10. }
  11. }
  12. }
  13. }
  14.  
  15. int main() {
  16. int n;
  17. printf("Enter the size of the array: ");
  18. scanf("%d", &n);
  19.  
  20. int arr[n];
  21. printf("Enter the elements of the array: ");
  22. for (int i = 0; i < n; i++) {
  23. scanf("%d", &arr[i]);
  24. }
  25.  
  26. sortArray(arr, n);
  27.  
  28. printf("Sorted array in descending order: ");
  29. for (int i = 0; i < n; i++) {
  30. printf("%d ", arr[i]);
  31. }
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5304KB
stdin
6
1 10 4 6 7 8 
stdout
Enter the size of the array: Enter the elements of the array: Sorted array in descending order: 10 8 7 6 4 1