Advertisement
d1i2p3a4k5

3.transpose of square matrix

Oct 18th, 2014
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.lang.*;
  2. import java.util.*;
  3. class transpose
  4. {
  5.     public static void main(String args[])
  6.     {
  7.         Scanner t  = new Scanner (System.in);
  8.         System.out.println("enter n ");
  9.         int n = t.nextInt();
  10.         int i,k,l,temp,j;
  11.         int a[][] = new int[n][n];
  12.         System.out.println("enter elements of matrix ");
  13.         for(i=0;i<n;i++)
  14.         {
  15.             for(j=0;j<n;j++)
  16.             {
  17.                 a[i][j] = t.nextInt();
  18.             }
  19.         }
  20.         System.out.println("original matrix of order n*n is given below:");
  21.         for(i=0;i<n;i++)
  22.         {
  23.             for(j=0;j<n;j++)
  24.             {
  25.                 System.out.print(a[i][j]+"  ");
  26.             }
  27.             System.out.println();
  28.         }
  29.        
  30.         for(i=0;i<n;i++)
  31.         {
  32.             for(j=0;j<=i;j++)
  33.             {
  34.                 temp=a[j][i];
  35.                 a[j][i]=a[i][j];
  36.                 a[i][j]=temp;
  37.             }
  38.         }
  39.         System.out.println("TRANSPOSE of entered matrix is given below : ");
  40.         for(i=0;i<n;i++)
  41.         {
  42.             for(j=0;j<n;j++)
  43.             {
  44.                 System.out.print(a[i][j]+"  ");
  45.             }
  46.             System.out.println();
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement