Write a program to find transpose of a matrix

A matrix is taken from user.. and its Transpose is displayed as output..


Select To use this code as it is.. select and copy paste this code into code.cpp file :)



  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. clrscr();
  6. int a[10][10],m,n,i,j;
  7. cout<<"Enter number of rows: ";
  8. cin>>m;
  9. cout<<"Enter number of coloumns: ";
  10. cin>>n;
  11. //Coding by: Snehil Khanor
  12. //http://WapCPP.blogspot.com
  13. if(m!=n)
  14. {
  15. cout<<"Matrix not square so Transpose not possible :(";
  16. }
  17. else
  18. {
  19. cout<<endl<<"Enter elements of matrix: "<<endl;
  20. for(i=0;i<m;i++)
  21. {
  22. for(j=0;j<n;j++)
  23. {
  24. cout<<"Enter element a"<<i+1<<j+1<<": ";
  25. cin>>a[i][j];
  26. }
  27. }
  28. cout<<endl<<"Displaying Matrix: "<<endl<<endl;
  29. for(i=0;i<m;i++)
  30. {
  31. for(j=0;j<n;j++)
  32. {
  33. cout<<a[i][j]<<" ";
  34. }
  35. cout<<endl<<endl;
  36. }
  37. cout<<endl<<"Displaying Matrix Transpose: "<<endl<<endl;
  38. for(i=0;i<m;i++)
  39. {
  40. for(j=0;j<n;j++)
  41. {
  42. cout<<a[j][i]<<" ";
  43. }
  44. cout<<endl<<endl;
  45. }
  46. }
  47. getch();
  48. }

Check out this stream