NAME: CHUKWUEMEKA ESTHER NMESOMA
MATRIC NO: 2022/11575
DEPT: COMPUTER ENGINEERING
CEN 301 ASSIGNMENT
Develop a program to find the transpose of a matrix.
#include <stdio.h>
int main() {
int rows, cols, i, j;
printf("Enter the number of rows and columns of the matrix: ");
scanf("%d %d", &rows, &cols);
int matrix[rows][cols];
printf("Enter the elements of the matrix:\n");
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
scanf("%d", &matrix[i][j]);
}
}
int transpose[cols][rows];
// Transpose the matrix
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
transpose[i][j] = matrix[j][i];
}
}
printf("Transpose of the matrix:\n");
for (i = 0; i < cols; i++) {
for (j = 0; j < rows; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}