Latest courses

Transpose of a matrix in C

In this example, You learn about transpose of a matrix in C. 

Here you learn c program to find transpose of a matrix, You are given a matrix and the task of the program to find transpose of matrix.

C Program to Find Transpose of a Matrix

#include<stdio.h>
 
int main() {
	
	int i,j,rows,cols;
	
	printf("How many Rows:");
	scanf("%d",&rows);
	printf("How many Columns:");
	scanf("%d",&cols);
	
	int A[rows][cols];
	
	printf("\nEnter the matrix:\n");
	for(i=0;i<rows;i++)
		for(j=0;j<cols;j++)
			scanf("%d",&A[i][j]);
			
	printf("\nTranspose of given matrix:\n");
	
	for(i=0;i<rows;i++)
	{
		for(j=0;j<cols;++j)
		printf("%d ",A[j][i]);
		printf("\n");
	}
	return 0;
}

Output


 How many Rows:3
 How many Columns:3

 Enter the matrix:
 9 8 7
 6 5 4
 3 2 1

 Transpose of given matrix:
 9 6 3
 8 5 2
 7 4 1

No comments:

If you have any doubts, Please let me know

Powered by Blogger.