Skip to main content

C++ Program to Find transpose of a matrix


C++ Program to Find transpose of a matrix


 #include <iostream>

using namespace std;


int main() {

   int a[10][10], transpose[10][10], row, column, i, j;


   cout << "Enter rows and columns of matrix: ";

   cin >> row >> column;


   cout << "\nEnter elements of matrix: " << endl;


   // Storing matrix elements

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

      for (int j = 0; j < column; ++j) {

         cout << "Enter element a" << i + 1 << j + 1 << ": ";

         cin >> a[i][j];

      }

   }


   // Printing the a matrix

   cout << "\nEntered Matrix: " << endl;

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

      for (int j = 0; j < column; ++j) {

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

         if (j == column - 1)

            cout << endl << endl;

      }

   }


   // Computing transpose of the matrix

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

      for (int j = 0; j < column; ++j) {

         transpose[j][i] = a[i][j];

      }


   // Printing the transpose

   cout << "\nTranspose of Matrix: " << endl;

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

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

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

         if (j == row - 1)

            cout << endl << endl;

      }


   return 0;

}


---------------------------------

Output


Enter rows and columns of matrix: 2

3


Enter elements of matrix:

Enter element a11: 1

Enter element a12: 2

Enter element a13: 9

Enter element a21: 0

Enter element a22: 4

Enter element a23: 7


Entered Matrix:

1  2  9


0  4  7



Transpose of Matrix:

1  0


2  4


9  7

Comments

Popular posts from this blog

Dalton's Atomic Theory—(Chemistry)

Dalton's Atomic Theory The theory that' all matter is made up of very tiny indivisible particles (atoms)' is called atomic theory of matter. Dalton's put forward his Atomic Theory of matter in 1808. The various postulates of Dalton's atoAto Theory of matter are as follows: All the matter is made up of very small particles called 'atoms'. Atoms cannot be divided. Atoms can neither be created nor destroyed Atoms are of various kinds. There are as many kinds of atoms as are elements. All the atoms of a given element are identical in every respect, having the same mass, size and chemical properties. Atoms of different elements differ in mass, size and chemical properties. Chemical combination between two elements consists in the joining together of atoms of these elements to form molecules of compounds. Drawbacks of Dalton's Atomic Theory It is now known that some of the statements of Dalton's Atomic Theory of matter are not exactly corre...

What is HTML or HTML tags

HTML 1) HTML stands for Hyper Text Markup Language 2) Created by Ten Berners-Lie in 1991 but published in 1995 3) It is Client side web technology. 4) It has predefined elements are called tags, used to"markup" a text documents. HTML TAGS 1 <html>_____</html>     Declare the Web page to be written in HTML. 2 <head>_____</head>       Delimits the pages head. 3 <title>______</title>       Defines the title.(not display on the page) 4 <body>_____</body>      Delimits the pages body. 4 <hn>_____</hn>      Delimits a level in heading. 5 <b>_____</b>      Set in boldface 6 <i>_____</i>       Set in italics. 7 <center>_____</center>      Center on the page horizontal. 8 <ul>_____</ul>     ...

Is claims responsibility for Niger attack which killed 71

NIAMEY, Dec 13 (AFP) The Islamic state group has claimed responsibility for an attack on an Army camp in Niger which left 71 military personnel dead, the SITE Intelligence group said on Thursday.    Hundreds of jihadists attacked the camp, near the border with Mali with shells and mortars on Tuesday, killed 71, injuring 122 and leaving other missing' according to the Defence Ministry. The attack in Inates in the western Tillaberi region was the deadliest on Nigers military since Islamist militant violence began to spill over from neighbouring Mali in 2015. "The Islamic States West Africa Province (ISWAP) claimed credit for the deadly raid on the Inates military base in Niger, "SITE, which monitors jihadist media, said.