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 :: c++ tokenize string 
Cpp :: convert string to lpwstr 
Cpp :: find max element in array c++ 
Cpp :: c++ cast char to string 
Cpp :: coordinate in 1d array c++ 
Cpp :: ViewController import 
Cpp :: c++ default parameters 
Cpp :: time_t to int 
Cpp :: delete from front in vector c++ 
Cpp :: convert decimal to binary in c++ 
Cpp :: priority queue c++ 
Cpp :: string to uint64_t c++ 
Cpp :: how to declare a 2d boolean vector in c++ 
Cpp :: how to find the size of a character array in c++ 
Cpp :: throw exception c++ 
Cpp :: case label in c++ 
Cpp :: stoi function in c++ library 
Cpp :: C++ Vector Operation Add Element 
Cpp :: how to get the time in c++ as string 
Cpp :: c++ struct 
Cpp :: sort array c++ 
Cpp :: c++ capture screen as pixel array 
Cpp :: C++ code for Dijkstra’s Algorithm 
Cpp :: Max element in an array with the index in c++ 
Cpp :: set to vector 
Cpp :: cpp detect os 
Cpp :: c++ pointers and functions 
Cpp :: access last element of set c++ 
Cpp :: cpp linked list 
Cpp :: take a function as an argument in c++ 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =