Computer >> 컴퓨터 >  >> 프로그램 작성 >> C++

그래프 행렬의 전치를 찾는 C++ 프로그램

<시간/>

이 프로그램에서 우리는 행렬을 취하고 행렬의 전치를 인쇄합니다. 전치 행렬에서 행은 열이 되고 그 반대도 마찬가지입니다.

알고리즘

Begin
   Take number of rows and columns of the matrix.
   Take The elements of the matrix and stored in the matrix ‘A’.
   The transpose matrix is found by exchanging the rows with columns and columns with rows.
   Print both the original matrix and the transpose.
End.

예시 코드

#include<iostream>
using namespace std;
int main () {
   int A[10][10], a, b, i, j;
   cout << "Enter rows and columns of matrix : ";
   cin >> a>> b;
   cout << "Enter elements of matrix : ";
   for (i = 0; i < a; i++)
      for (j = 0; j < b; j++)
         cin >> A[i][j];
      cout << "Entered Matrix : \n ";
      for (i = 0; i < a; i++) {
         for (j = 0; j < b; j++)
            cout << A[i][j] << " ";
         cout << "\n ";
      }
      cout << "Transpose of Matrix : \n ";
      for (i = 0; i < b;) {
         for (j = 0; j < a; j++)
            cout << A[j][i] << " ";
         cout << "\n ";
      }
      return 0;
}

출력

Enter rows and columns of matrix:3 3
Enter elements of matrix : 6 7 1 3 2 5 9 12 11
Entered Matrix :
6 7 1
3 2 5
9 12 11
Transpose of Matrix :
6 3 9
7 2 12
1 5 11