fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int arr[4][4]={{1,2,3,4},{5,6,7,8},{7,8,9,10},{8,9,10,11}};
  7. int row= sizeof(arr)/sizeof(arr[0]);
  8. int col= sizeof(arr[0])/sizeof(arr[0][0]);
  9.  
  10. cout<<"Matrix is:\n";
  11. for(int i=0;i<row;i++){
  12. for(int j=0;j<col;j++){
  13. cout<<arr[i][j]<<" ";
  14. }
  15. cout<<endl;
  16. }
  17.  
  18.  
  19. for(int i=0;i<row;i++){
  20. for(int j=i+1;j<col;j++){
  21. swap(arr[i][j], arr[j][i]);
  22. }
  23. }
  24.  
  25. cout<<"Matrix transpose is:\n";
  26. for(int i=0;i<row;i++){
  27. for(int j=0;j<col;j++){
  28. cout<<arr[i][j]<<" ";
  29. }
  30. cout<<endl;
  31. }
  32. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Matrix is:
1 2 3 4 
5 6 7 8 
7 8 9 10 
8 9 10 11 
Matrix transpose is:
1 5 7 8 
2 6 8 9 
3 7 9 10 
4 8 10 11