Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.*;
- import java.util.*;
- class transpose
- {
- public static void main(String args[])
- {
- Scanner t = new Scanner (System.in);
- System.out.println("enter n ");
- int n = t.nextInt();
- int i,k,l,temp,j;
- int a[][] = new int[n][n];
- System.out.println("enter elements of matrix ");
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- a[i][j] = t.nextInt();
- }
- }
- System.out.println("original matrix of order n*n is given below:");
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- System.out.print(a[i][j]+" ");
- }
- System.out.println();
- }
- for(i=0;i<n;i++)
- {
- for(j=0;j<=i;j++)
- {
- temp=a[j][i];
- a[j][i]=a[i][j];
- a[i][j]=temp;
- }
- }
- System.out.println("TRANSPOSE of entered matrix is given below : ");
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- System.out.print(a[i][j]+" ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement