C++ program to swap or transpose a matrix by using multi-dimensional arrays. Using this program to print the transpose of the matrix. A matrix is a rectangular array of numbers that are arranged in rows and columns. The numbers are referred to as the matrix’s elements or entries. Engineering, physics, economics, and statistics, as well as various disciplines of mathematics, all use matrices.

#include<iostream>

using namespace std;

int row,col;

int main()

{

int val,row,col;

cin>>row;

cin>>col;

int a[row][col];

cout<<"\n a: \n";

for(int i=0;i<row;i++)

{

for(int j=0;j<col;j++)

{

cin>>val;

a[i][j]=val;

}

}

int b[col][row];

for(int j=0;j<row;j++)

{

for(int i=0;i<col;i++)

b[i][j]=a[j][i];

}

for(int i=0;i<col;i++)

{

for(int j=0;j<row;j++)

a[i][j]=b[i][j];

}

for(int i=0;i<col;i++)

{

for(int j=0;j<row;j++)

cout<<a[i][j]<<" ";

cout<<"\n";

}

return 0;

}

Output:

2

2

a:

34

45

56

67

34 56

45 67

## What is matrix and how to implement in c++ program

A matrix is a set of numbers organized into a predetermined number of rows and columns. The numbers are usually real numbers. Complex numbers can be found in matrices in general, but we won’t encounter them here. An example of a three-row, three-column matrix is as follows: Row 1 is at the top of the list.

## What is transpose matrix and how to implement in c++ program

“A Matrix that is generated by changing all the rows of a given matrix into columns and vice versa,” according to the definition. Given a matrice of order 43, find the solution. The transpose of a matrix is achieved by swapping rows and columns. A matrix is “flipped” over its diagonal. The rows and columns are switched around. The value in the first row and third column, for example, ends up in the third row and first column.

## What is namespace in c++ program

A namespace is a C++ feature that is not available in C. A namespace is a declarative zone that gives the identifiers (names of types, functions, variables, and so on) within it a scope. It is permissible to have many namespace blocks with the same name. The named scope is used for all declarations within those blocks.

## Similar Programs

**Java code for car parking management system**** **

**Java program to find the middle element of the string**** **

**Java program to find the cubes of an n natural numbers**** **

**Java program to print weekdays using a switch statement**** **

**Java program to solve quadratic equation using if-else**** **

**Java program calculation to fill the bucket with the water mug**** **

**Method Overloading in Java to Find Arithmetic Sum of 2 or 3 or 4 Variables by Passing Argument**** **

**Write a java program to print the nested methods to perform mathematical operations**** **

**How to print semicolon in java program without using it**** **

**Write a java program to find the largest number in an array**** **

**Write a java program to delete an element from an array list at the specified index**

**Write a java program to arrange strings in alphabetical order**** **

**Write a java program to split an array in a specific position**** **

**Write a array program to calculate average and sum in java**** **

**Write a program to calculate electricity bill in java**** **

**Find out duplicate number between 1 to n numbers in java**** **

**Program in java to print the pie value(pi)**** **

**Java program to print the element using calling methods in the same class**