-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixmult.java
More file actions
58 lines (39 loc) · 1.27 KB
/
Copy pathmatrixmult.java
File metadata and controls
58 lines (39 loc) · 1.27 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Scanner;
public class matrixmult {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("enter the no. of rows");
int r = sc.nextInt();
System.out.println("enter the no. of column");
int c = sc.nextInt();
int[][] arr = new int[r][c];
int[][] brr = new int[r][c];
int[][] result = new int[r][c];
System.err.println("enter the first array ");
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
arr[i][j] = sc.nextInt();
}
}
System.err.println("enter the second array ");
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
brr[i][j] = sc.nextInt();
}
}
for (int i = 0; i < r; i++) {
for (int j = 0; j < c;j++){
for(int k =0; k < c ;k++){
result[i][j] = result[i][j] + arr[i][k]*brr[k][j];
}
}
}
for(int i = 0 ; i < r; i++){
for(int j = 0; j < c; j++){
System.out.print(result[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}