c program to find the transpose of a matrix

Description


This program finds the transpose of a matrix.The row and column values of the matrix is read into the variables r and c, then the elements are read into the matrix a[][] using the for loop. Then the program uses another for loop to print the matrix column wise, this gives the transpose of the matrix. Below is an example of the transpose of a matrix.

Example


Original matrix

2  2  6
4  8  2
4  5  6

Transpose of the matrix

4  4  2
5  8  2
6  2  6

Program


#include<stdio.h>

#include<conio.h>

void main()

{

clrscr();

int r,c,a[50][50],i,j;

printf("Enter the row value and cloum value\n");

scanf("%d%d",&r,&c);

printf("Enter the elements of matrix\n");

for(i=0;i<r;i++)

{

for(j=0;j<c;j++)

{

scanf("%d",&a[i][j]);

}}

printf("Transpose of matrix\n");

for(j=0;j<c;j++)

{

for(i=0;i<r;i++)

{

printf("%d ",a[i][j]);

}

printf("\n");

}

getch();

}


Related post:- C++ program to find the transpose of a matrix and check whether it is symmetric or not

No comments: