Write C++ Program to Find the Transpose of a given Matrix


I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Introduction

I have used CodeBlocks compiler for debugging purpose. But you can use any C++ programming language compiler as per your availability.


  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. static int array[10][10];
  7. int i, j, m, n;
  8.  
  9. cout<<"Enter the order of the matrix \n";
  10. // Inputing elements in matrix from user
  11. cin>>m>>n;
  12. cout<<"Enter the coefiicients of the matrix\n";
  13. for (i = 0; i < m; ++i)
  14. {
  15. for (j = 0; j < n; ++j)
  16. {
  17. cin>>array[i][j];
  18. }
  19. }
  20. //Printing the original matrix
  21. cout<<"The given matrix is \n";
  22. for (i = 0; i < m; ++i)
  23. {
  24. for (j = 0; j < n; ++j)
  25. {
  26. cout<<" "<<array[i][j];
  27. }
  28. cout<<"\n";
  29. }
  30. //Printing the transpose of matrix
  31. cout<<"Transpose of matrix is \n";
  32. for (j = 0; j < n; ++j)
  33. {
  34. for (i = 0; i < m; ++i)
  35. {
  36. cout<<" "<<array[i][j];
  37. }
  38. cout<<"\n";
  39. }
  40. return 0;
  41. }
  42.  
  43.  

Result

C++ language techstudy.org

     





Related Topics




Popular Posts