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. }

advertisement
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
If you wish to look at all C++ Programming examples, go to C++ Programs.

advertisement
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He is Linux Kernel Developer & SAN Architect and is passionate about competency developments in these areas. He lives in Bangalore and delivers focused training sessions to IT professionals in Linux Kernel, Linux Debugging, Linux Device Drivers, Linux Networking, Linux Storage, Advanced C Programming, SAN Storage Technologies, SCSI Internals & Storage Protocols such as iSCSI & Fiber Channel. Stay connected with him @ LinkedIn