/* This is HW4_7 Lab EE107
The purpose of this function for transpose matrix
Creating the code and free of syntax and grammatical errors.
Author: Ekwegbalum Unachukwu
Star ID:do2170dt
Due Date: April 26th, 2024.
*/
#include <stdio.h>

// Function to transpose a matrix of size 4x5
void transposeMatrix_EU(int mat_4x5_EU[4][5], int mat_5x4_EU[5][4]) {
    // Transpose the matrix
    for (int i_EU = 0; i_EU < 4; i_EU++) {
        for (int j_EU = 0; j_EU < 5; j_EU++) {
            mat_5x4_EU[j_EU][i_EU] = mat_4x5_EU[i_EU][j_EU];
        }
    }
}

int main() {
    // Define the 4x5 matrix
    int matrix_4x5_EU[4][5] = {
        {1, 2, 3, 4, 5},
        {6, 7, 8, 9, 10},
        {11, 12, 13, 14, 15},
        {16, 17, 18, 19, 20}
    };

    // Define the 5x4 matrix
    int matrix_5x4_EU[5][4];

    // Print the original matrix (4x5)
    printf("Original Matrix (4x5):\n");
    for (int i_EU = 0; i_EU < 4; i_EU++) {
        for (int j_EU = 0; j_EU < 5; j_EU++) {
            printf("%d ", matrix_4x5_EU[i_EU][j_EU]);
        }
        printf("\n");
    }

    // Transpose the 4x5 matrix
    transposeMatrix_EU(matrix_4x5_EU, matrix_5x4_EU);

    // Print the transposed matrix (5x4)
    printf("\nTransposed Matrix (5x4):\n");
    for (int i_EU = 0; i_EU < 5; i_EU++) {
        for (int j_EU = 0; j_EU < 4; j_EU++) {
            printf("%d ", matrix_5x4_EU[i_EU][j_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: