/******************************************************************************
Welcome to blackNwhite
Question:- Write a C program to find transpose of a matrix .
*******************************************************************************/
#include <stdio.h>
#define MAX_ROWS 10
#define MAX_COLS 10
int main() {
int matrix[MAX_ROWS][MAX_COLS], transpose[MAX_ROWS][MAX_COLS];
int rows, cols, i, j;
printf("Enter the number of rows and columns of the matrix: ");
scanf("%d %d", &rows, &cols);
printf("Enter elements of the matrix:\n");
// Input matrix elements
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("Enter element matrix[%d][%d]: ", i, j);
scanf("%d", &matrix[i][j]);
}
}
// Finding the transpose of the matrix
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
transpose[j][i] = matrix[i][j];
}
}
// Displaying the original matrix
printf("\nOriginal Matrix:\n");
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
// Displaying the transpose of the matrix
printf("\nTranspose of the Matrix:\n");
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
printf("%d\t", transpose[i][j]);
}
printf("\n");
}
return 0;
}