-
-
Notifications
You must be signed in to change notification settings - Fork 122
Expand file tree
/
Copy pathtranspose.java
More file actions
33 lines (25 loc) · 791 Bytes
/
transpose.java
File metadata and controls
33 lines (25 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Program to transpose a matrix
import java.util.Scanner;
public class transpose {
public static void main(String argv[]) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of matrix: ");
int size = sc.nextInt();
int matrix[][] = new int[size][size];
System.out.println("Enter the elements of the matrix: ");
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
matrix[i][j] = sc.nextInt();
}
System.out.println();
}
int transpose_matrix[][] = new int[size][size];
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++) {
transpose_matrix[i][j] = matrix[j][i];
System.out.print(transpose_matrix[i][j]);
}
System.out.println();
}
}
}