Tuesday, February 10, 2015

Matrix Transpose

/* Write a C program to find the transpose of a matrix */ #include<stdio.h> int main() { int a[10][10], b[10][10], i, j, k=0, m, n; printf("Enter the row and column of matrix: "); scanf("%d %d", &m, &n); printf("\nEnter the matrix:\n"); for(i=0; i<m; i++) for(j=0; j<n; j++) scanf("%d", &a[i][j]); printf("\nThe matrix is:\n"); for(i=0; i<m; i++) { printf("\n"); for(j=0; j<m; j++) { printf("%d\t", a[i][j]); } } for(i=0; i<m; i++) for(j=0; j<n; j++) b[i][j] = 0; for(i=0; i<m; i++) { for(j=0; j<n; j++) { b[i][j] = a[j][i]; } } printf("\n\nTranspose of the matrix is: \n"); for(i=0; i<m; i++) { printf("\n"); for(j=0; j<m; j++) { printf("%d\t", b[i][j]); } } getch(); return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar