/* This is the eleventh lab of Lab EE107
The purpose of this lab for a function that display a variable-
length two-dimensional array, and another one that multiplies each
array element with a constant.

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 display a variable-length two-dimensional array
void display_array_EU(int rows_EU, int cols_EU, int arr_EU[rows_EU][cols_EU]) {
    for (int i = 0; i < rows_EU; i++) {
        for (int j = 0; j < cols_EU; j++) {
            printf("%d\t", arr_EU[i][j]);
        }
        printf("\n");
    }
}

// Function to multiply each element of the array by a constant
void multiply_by_constant_EU(int rows_EU, int cols_EU, int arr_EU[rows_EU][cols_EU], int constant_EU) {
    for (int i = 0; i < rows_EU; i++) {
        for (int j = 0; j < cols_EU; j++) {
            arr_EU[i][j] *= constant_EU;
        }
    }
}

int main() {
    //creating a storage for rows and columns
    int rows_EU = 3;
    int cols_EU = 3;
    //initiazing the size of the array, in rows and columns
    int arr_EU[3][3] = {
        {1, 2, 3},
        {4, 5, 6},
        {7, 8, 9}
    };

    printf("Original Array:\n");
    display_array_EU(rows_EU, cols_EU, arr_EU);
    
    //using for the function "constant".
    int constant_EU = 2;
    multiply_by_constant_EU(rows_EU, cols_EU, arr_EU, constant_EU);
    
//printing out the output for the function "constant".
    printf("\nArray after multiplication by %d:\n", constant_EU);
    display_array_EU(rows_EU, cols_EU, arr_EU);

    return 0;
}

Embed on website

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