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, then display the transpose of the matrix on the screen as shown here in the following C++ program.

C++ Programming Code to Transpose Matrix

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

/* C++ Program - Transpose Matrix */
		
#include<iostream.h>
#include<conio.h>
void main()
{
	clrscr();
	int arr[3][3], i, j, arrt[3][3];
	cout<<"Enter 3*3 Array Elements : ";
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			cin>>arr[i][j];
		}
	}
	cout<<"Transposing Array...\n";
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			arrt[i][j]=arr[j][i];
		}
	}
	cout<<"Transpose of the Matrix is :\n";
	for(i=0; i<3; i++)
	{
		for(j=0; j<3; j++)
		{
			cout<<arrt[i][j];
		}
		cout<<"\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 Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test