Simple Transpose (Contest)

Simple Transpose easy Time Limit: 2 sec Memory Limit: 128000 kB

Problem Statement :

You are given a NxN matrix. You need to find the transpose of the matrix. The matrix is of form: a b c ... d e f ... g h i ... ........... There are N elements in each row.InputThe first line of the input contains an integer N denoting the size of the square matrix. The next N lines contain N single-spaced integers. Constraints 1 <= N <= 100 1 <=Ai <= 100000OutputOutput the transpose of the matrix in similar format as that of the input.ExampleSample Input 2 1 3 2 2 Sample Output 1 2 3 2 Sample Input: 1 2 3 4 Sample Output: 1 3 2 4

link:https://my.newtonschool.co/playground/code/tbm42f392vrg/

```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework

// don't change the name of this class
// you can add inner classes if needed
class Main {
    public static void main (String[] args) {
        // Your code here
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[][] = new int[n][n];
        for(int r =0; r<n;r++){
            for(int c=0;c<n;c++){
                arr[r][c] = sc.nextInt();
            }
        }
        for(int r=0;r<n;r++){
            for(int c=0;c<n;c++){
                System.out.print(arr[c][r]+" ");
            }
            System.out.println();
        }
    }
}
```

Last updated