codescracker


c

C Program to Transpose Matrix



« Previous Program Next Program »


Transpose Matrix in C

To transpose any matrix in C programming language, you have to first ask to the user to enter the matrix and replace row by column and column by row to transpose that matrix and display the transpose of the matrix on the output screen as shown in the following program.

C Programming Code to Transpose Matrix

Following C program ask to the user to enter 3*3 array element to transpose and display the transpose of the matrix/array on the screen:

/* C Program - Transpose Matrix */
		
#include<stdio.h>
#include<conio.h>
void main()
{
	clrscr();
	int arr[3][3], i, j, arrt[3][3];
	printf("Enter 3*3 Array Elements : ");
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			scanf("%d",&arr[i][j]);
		}
	}
	printf("Transposing Array...\n");
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			arrt[i][j]=arr[j][i];
		}
	}
	printf("Transpose of the Matrix is :\n");
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			printf("%d ",arrt[i][j]);
		}
		printf("\n");
	}
	getch();
}

When the above c program is compile and executed, it will produce the following result:

c program transpose matrix

Same Program in Other Programming Language

You may also like same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test