C Program to Find the Transpose of a Matrix

Subject: PPS (Programming for Problem Solving)

Contributed By: Sanjay

Created At: February 3, 2025

Question:


Write a C Program to Find the Transpose of a Matrix

Explanation Video:

Custom Image

Explanation:

 

 

Source Code:
#include <stdio.h>

int main() {
    int arr[2][2] = {{1, 2}, {3, 4}}, trans[2][2];

    for (int i = 0; i < 2; i++)
        for (int j = 0; j < 2; j++)
            trans[j][i] = arr[i][j];

    printf("Transpose of the matrix:\n");
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++)
            printf("%d ", trans[i][j]);
        printf("\n");
    }
    return 0;
}
Output:
Transpose of the matrix:
1 3
2 4
Share this Article & Support Us:
Status
printf('Loading...');