-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path_3a.MatrixMultiplication.java
More file actions
47 lines (44 loc) · 1.16 KB
/
_3a.MatrixMultiplication.java
File metadata and controls
47 lines (44 loc) · 1.16 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
import java.io.*;
import java.util.*;
class Matrixmulti
{
public static void main(String[] args)
{
int A[][] = new int[10][10];
int B[][] = new int[10][10];
int C[][] = new int[10][10];
int i,j,k,r1,c1,r2,c2;
Scanner ob= new Scanner(System.in);
System.out.println(" Enter the no. of rows and columns of 1st matrix ");
r1 = ob.nextInt();
c1 = ob.nextInt();
System.out.println(" Enter the no. of rows and columns of 2nd matrix ");
r2 = ob.nextInt();
c2 = ob.nextInt();
if(c1 == r2){
System.out.println(" Enter the elements of 1st matrix: ");
for(i=0; i<r1; i++){
for(j=0 ; j<c1; j++){
A[i][j]= ob.nextInt();
}
}
System.out.println(" Enter the elements of 2nd matrix: ");
for(i=0; i<r2; i++){
for(j=0 ; j<c2; j++){
B[i][j]= ob.nextInt();
}
}
System.out.println(" Product of Matrices: ");
for(i=0; i<r1; i++){
for(j=0; j<c2 ; j++){
C[i][j]=0;
for(k=0 ; k<c1;k++){
C[i][j] = C[i][j] + A[i][k]*B[k][j];
}
System.out.print(C[i][j]+" ");
}
System.out.println();
}
}
}
}