Program to print Transpose of a matrix in C language

The following program print the transpose of the matrix in C. The transpose of a matrix makes the row to column and column to row. If the matrix is in the form a[3][2] then the transpose of such a matrix will be a[2][3].

About the Code: The code is written in two dimensional array taking [3][2] matrix size. You can increase the size if you want to. The code has been executed in Kali OS and working good with gcc and also will work with Dev C++.

Code:

#include<stdio.h>
void main(){
	int a[3][2],b[2][3],i,j;
	printf("Enter value for matrix:");
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){

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

		}
	}
	printf("Matrix:\n");
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			printf("%d	",a[i][j]);
		}
					printf("\n");

	}
	for(i=0;i<3;i++){
		for(j=0;j<2;j++){
			b[j][i]=a[i][j];
					
		}}
		printf("Transpose Matrix:\n");
		for(i=0;i<2;i++){
		for(j=0;j<3;j++){
			printf("%d	",b[i][j]);
		}
					printf("\n");

	}
}

OUTPUT:

Program to print Transpose of a matrix in C language

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: