Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

transpose of a matrix in c

#include<stdio.h>
void main(){
    int row,column,i,j,mat[100][100],tra[100][100];

    printf("Enter number of rows of matrix : ");
    scanf("%d",&row);
    printf("Enter number of columns of matrix : ");
    scanf("%d",&column);
    
    printf("#### Matrix ####
");
    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            printf("Enter element a %d%d : ",i+1,j+1);
            scanf("%d",&mat[i][j]);
        }
    }

    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            tra[i][j] = mat[j][i];
        }
    }
    
    for(i=0;i<row;i++){
        for(j=0;j<column;j++){
            printf("%d ",tra[i][j]);
        }
        printf("
");
    }
    
}
 
PREVIOUS NEXT
Tagged: #transpose #matrix
ADD COMMENT
Topic
Name
8+1 =