fork download
  1. #include <stdio.h>
  2.  
  3. void sort_array(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 rows, cols;
  17.  
  18. printf("Enter the number of rows: ");
  19. scanf("%d", &rows);
  20.  
  21. printf("Enter the number of columns: ");
  22. scanf("%d", &cols);
  23.  
  24. int A[rows][cols];
  25.  
  26. printf("Enter the elements of the array:\n");
  27. for (int i = 0; i < rows; i++) {
  28. for (int j = 0; j < cols; j++) {
  29. scanf("%d", &A[i][j]);
  30. }
  31. }
  32.  
  33. sort_array(A[0], cols);
  34.  
  35. printf("Sorted first row in descending order:\n");
  36. for (int i = 0; i < cols; i++) {
  37. printf("%d ", A[0][i]);
  38. }
  39.  
  40. return 0;
  41. }
  42.  
Success #stdin #stdout 0s 5304KB
stdin
2
2
4 743 13 1
stdout
Enter the number of rows: Enter the number of columns: Enter the elements of the array:
Sorted first row in descending order:
743 4