-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram50.java
More file actions
77 lines (53 loc) · 1.97 KB
/
Copy pathprogram50.java
File metadata and controls
77 lines (53 loc) · 1.97 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// WAP to perform multiplication of two matrices..
import java.util.Scanner;
public class program50{
public static void main(String[] args) {
System.out.println("--------Matrix Multiplication------");
Scanner sc = new Scanner(System.in);
System.out.println("-- Matrix A --");
System.out.print("Enter R1 : ");
int R1 = sc.nextInt();
System.out.print("Enter C1 : ");
int C1 = sc.nextInt();
System.out.println("-- Matrix B --");
System.out.println("Enter R2 : ");
int R2 = sc.nextInt();
System.out.println("Enter C2 : ");
int C2 = sc.nextInt();
if (C1!=R2){
System.out.println("Multiplication Not Possible !!!!");
}
int [][]A = new int[R1][C1];
int [][]B = new int[R2][C2];
int [][]C = new int[R1][C2];
System.out.println("Enter Matrix A Elements : ");
for(int i =0; i<R1; i++){
for(int j =0; j<C1; j++){
A[i][j] = sc.nextInt();
}
}
System.out.println("Enter Matrix B Elements : ");
for(int i = 0; i<R2; i++){
for(int j = 0; j<C2; j++){
B[i][j] = sc.nextInt();
}
}
System.out.println("-- Multiplication Of Matrix A * B -- ");
for(int i =0; i<R1; i++){
for(int j = 0; j<C2; j++){
C[i][j] = 0;
for(int k =0; k<C1; k++){
C[i][j] += A[i][k] * B[k][j];
}
}
}
System.out.println("-- Displaying Result -- ");
for(int i =0; i<R1; i++){
for(int j =0; j<C2; j++){
System.out.print(C[i][j] + " ");
}
System.out.println();
}
sc.close();
}
}