-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMatrixTranspose.java
More file actions
37 lines (34 loc) · 928 Bytes
/
MatrixTranspose.java
File metadata and controls
37 lines (34 loc) · 928 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
34
35
36
37
import java.util.Scanner;
public class MatrixTranspose{
public static void main(String ar[]){
int[][] a= new int[10][10];
int[][] b= new int[10][10];
Scanner s1 = new Scanner(System.in);
System.out.print("Enter Number of Rows : ");
int rows = s1.nextInt();
System.out.print("Enter Number of Columns : ");
int columns = s1.nextInt();
for(int i=0;i<rows;i++)
for(int j=0;j<columns;j++)
a[i][j] = s1.nextInt();
System.out.println("Matrix elements are as follows :");
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
System.out.print(a[i][j]+" ");
}
System.out.println("");
}
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
b[i][j]=a[j][i];
}
}
System.out.println("Elements After Transposition of Matrix are as follows:");
for(int i=0;i<rows;i++){
for(int j=0;j<columns;j++){
System.out.print(b[i][j]+" ");
}
System.out.println("");
}
}
}