Guest User

Rangga transpose

a guest
Nov 12th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class TransposeAMatrix
  4. {
  5. public static void main(String args[])
  6. {
  7. int m, n, c, d;
  8.  
  9. Scanner in = new Scanner(System.in);
  10. System.out.println("rows and columns of matrix");
  11. m = in.nextInt();
  12. n = in.nextInt();
  13.  
  14. int matrix[][] = new int[m][n];
  15.  
  16. System.out.println("Enter the elements of matrix");
  17.  
  18. for ( c = 0 ; c < m ; c++ )
  19. for ( d = 0 ; d < n ; d++ )
  20. matrix[c][d] = in.nextInt();
  21.  
  22. int transpose[][] = new int[n][m];
  23.  
  24. for ( c = 0 ; c < m ; c++ )
  25. {
  26. for ( d = 0 ; d < n ; d++ )
  27. transpose[d][c] = matrix[c][d];
  28. }
  29.  
  30. System.out.println("Transpose of entered matrix:-");
  31.  
  32. for ( c = 0 ; c < n ; c++ )
  33. {
  34. for ( d = 0 ; d < m ; d++ )
  35. System.out.print(transpose[c][d]+"\t");
  36.  
  37. System.out.print("\n");
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment