Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c++ program transpose of 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 << "
Enter 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 << "
Entered 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 << "
Transpose 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;
}
Comment

transpose matrix c++ vectors

vector<vector<double>> outtrans(out[0].size(),
                                    vector<double>(out.size()));
    for (size_t i = 0; i < out.size(); ++i)
        for (size_t j = 0; j < out[0].size(); ++j)
            outtrans[j][i] = out[i][j];
Comment

PREVIOUS NEXT
Code Example
Cpp :: string in cpp 
Cpp :: print 2d array c++ 
Cpp :: count bits c++ 
Cpp :: string to int c++ 
Cpp :: on component begin overlap c++ 
Cpp :: array max and minimum element c++ 
Cpp :: comparator for priority queue c++ 
Cpp :: append string cpp 
Cpp :: matrix in vector c++ 
Cpp :: c++ get string between two characters 
Cpp :: how to sort a string alphabetically in c++ 
Cpp :: c++ string element access 
Cpp :: create copy constructor c++ 
Cpp :: c++ output 
Cpp :: who to include a library c++ 
Cpp :: cannot jump from switch statement to this case label c++ 
Cpp :: stoi() c++ 
Cpp :: hello world in c/++ 
Cpp :: cin getline 
Cpp :: str remove char c++ 
Cpp :: cpp float 
Cpp :: sum of row s2 d array c++ 
Cpp :: c++ char array size 
Cpp :: sum of a matrix c++ 
Cpp :: constructor in cpp 
Cpp :: c++ #define 
Cpp :: array of struct in c++ 
Cpp :: map count function c++ 
Cpp :: run c++ program mac 
Cpp :: comparator priority queue c++ 
ADD CONTENT
Topic
Content
Source link
Name
6+5 =