Transpose of Matrix in C program
#include <stdio.h>
#include <stdlib.h>
int main (){
int r, c, i, j, matrix[20][20], transpose[20][20];
/*Transpose matrix program*/
printf(" Position : Transpose of a Matrix\n\n");
printf("Enter the size of matrix ");
scanf("%d%d",&r,&c);
printf("Enter the elements of matrix \n");
for( int i=0 ; i<r ; i++ ){
for( int j=0 ; j<c ; j++ ){
printf("[%d][%d]",i,j);
scanf("%d",&matrix[i][j]);
}
}
printf("the matrix is:\n");
for (i=0 ; i<r ; i++){
for (j=0 ; j<c ; j++){
printf("%d\t",matrix[i][j]);
}
printf("\n");
}
for( int i=0 ; i<r ; i++ ){
for( int j=0 ; j<c ; j++ ){
transpose[i][j] = matrix[j][i];
}
}
printf("Transpose of entered matrix :\n");
for( int i=0 ; i<r ; i++ ){
for( int j=0 ; j<c ; j++ ){
printf("%d\t",transpose[i][j]);
}
printf("\n");
}
return 0;
}
output
0 Comments