forked from shivaylamba/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TransposeAMatrix.java
38 lines (28 loc) · 905 Bytes
/
TransposeAMatrix.java
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
34
35
36
37
38
import java.util.Scanner;
class TransposeAMatrix
{
public static void main(String args[])
{
int m, n, c, d;
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of rows and columns of matrix");
m = in.nextInt();
n = in.nextInt();
int matrix[][] = new int[m][n];
System.out.println("Enter the elements of matrix");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
matrix[c][d] = in.nextInt();
int transpose[][] = new int[n][m];
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
transpose[d][c] = matrix[c][d];
System.out.println("Transpose of the matrix:");
for (c = 0; c < n; c++)
{
for (d = 0; d < m; d++)
System.out.print(transpose[c][d]+"\t");
System.out.print("\n");
}
}
}