Skip to content

Commit

Permalink
Transpose of a Matrix in Cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishak798 authored Mar 12, 2024
1 parent 1636f4c commit 835b03c
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions Matrix_Questions/matrixtranspose.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
*
@file matrixtranspose.cpp
* @author your name ([email protected])
* @brief
* @version 0.1
* @date 2024-03-12
*
* @copyright Copyright (c) 2024
* Write a program in C to find the transpose of a given matrix.
Test Data :
Input the rows and columns of the matrix : 2 2
Input elements in the first matrix :
element - [0],[0] : 1
element - [0],[1] : 2
element - [1],[0] : 3
element - [1],[1] : 4
Expected Output :
The matrix is :
1 2
3 4
The transpose of a matrix is :
1 3
2 4
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout << "Enter size of Matrix: ";
cin >> n;
int arr[n][n];
int transposeMatrix[n][n];
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << "Enter element of array at " << i << " " << j << " : ";
cin >> arr[i][j];
}
cout << endl;
}
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
transposeMatrix[j][i] = arr[i][j];
}
}

cout << endl;
cout << "Matrix Transpose : [ " << endl;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
cout << transposeMatrix[i][j];
}
cout << endl;
}
cout << "]";
}
/**
Enter size of Matrix: 2
Enter element of array at 0 0 : 1
Enter element of array at 0 1 : 2
Enter element of array at 1 0 : 3
Enter element of array at 1 1 : 4
Matrix Transpose : [
13
24
]
**/

0 comments on commit 835b03c

Please sign in to comment.