C++ Program to Find Transpose of a Graph Matrix

This C++ program displays the transpose of a graph matrix

Here is the source code of the C++ program to display the augmented matrix along with the inverse of the matrix taken as input. This C++ program is successfully compiled and run on DevCpp, a C++ compiler. The program output is given below.

  1. /*
  2.  * C++ Program to Find Transpose of a Graph Matrix
  3.  */
  4. #include<iostream>
  5. #include<conio.h>
  6. #include<stdio.h>
  7. using namespace std;
  8. int main()
  9. {
  10.     int i, j, n;
  11.     int a[10][10] = {0},b[10][10] = {0};
  12.     cout<<"Enter the order of matrix ";
  13.     cin>>n;
  14.     cout<<"Enter the elements\n";
  15.     for (i = 1; i <= n; i++)
  16.     {
  17.         for (j = 1; j <= n; j++)
  18.         {
  19.             cin>>a[i][j];
  20.         }
  21.     }
  22.     for (i = 1; i <= n; i++)
  23.     {
  24.         for (j = 1; j <= n; j++)
  25.         {
  26.             b[j][i] = a[i][j];
  27.         }
  28.     }
  29.     cout<<endl<<"Original Matrix\n";
  30.     for (i = 1; i <= n; i++)
  31.     {
  32.         for (j = 1; j <= n; j++)
  33.         {
  34.             cout<<a[i][j]<<"    ";
  35.         }
  36.         cout<<endl;
  37.     }
  38.     cout<<endl<<"Transpose Matrix\n";
  39.     for (i = 1; i <= n; i++)
  40.     {
  41.         for (j = 1; j <= n; j++)
  42.         {
  43.             cout<<b[i][j]<<"    ";
  44.         }
  45.         cout<<endl;
  46.     }
  47.     getch();
  48. }

Output
 
Enter the order of matrix 3
Enter the elements
5
3
1
8
6
9
4
7
0
 
Original Matrix
5    3    1
8    6    9
4    7    0
 
Transpose Matrix
5    8    4
3    6    7
1    9    0

Sanfoundry Global Education & Learning Series – 1000 C++ Programs.

advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.