/* This is the eleventh lab of Lab EE107
The purpose of this lab for creating a function to sort an array in descending order.

Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Date: April 9th, 2024.
*/
#include <stdio.h>

// Function to sort an array in descending order using Bubble Sort
void sort_descending_EU(int arr_EU[], int size_EU) {
    int temp_EU;
    for (int i_EU = 0; i_EU < size_EU - 1; i_EU++) {
        for (int j_EU = 0; j_EU < size_EU - i_EU - 1; j_EU++) {
            if (arr_EU[j_EU] < arr_EU[j_EU + 1]) {
                // Swap elements if they are in the wrong order
                temp_EU = arr_EU[j_EU];
                arr_EU[j_EU] = arr_EU[j_EU + 1];
                arr_EU[j_EU + 1] = temp_EU;
            }
        }
    }
}

int main() {
    int arr_EU[] = {3, 9, 5, 4, 2, 6, 7};
    int size_EU = sizeof(arr_EU) / sizeof(arr_EU[0]);

    printf("Original Array:\n");
    for (int i_EU = 0; i_EU < size_EU; i_EU++) {
        printf("%d ", arr_EU[i_EU]);
    }
    printf("\n");

    // Sort the array in descending order
    sort_descending_EU(arr_EU, size_EU);

    printf("Array Sorted in Descending Order:\n");
    for (int i_EU = 0; i_EU < size_EU; i_EU++) {
        printf("%d ", arr_EU[i_EU]);
    }
    printf("\n");

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: