forked from hariom20singh/foodewbpage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix Multiplication
45 lines (35 loc) · 1.09 KB
/
Matrix Multiplication
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
package arrays;
import java.util.Scanner;
public class MatrixMultiplication {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Dimension ( n * n ) :-");
int n = sc.nextInt();
int a[][] = new int [n][n];
int b[][] = new int [n][n];
System.out.println("Enter array 1 :-");
for(int i = 0 ; i<n; i++) {
for(int j = 0 ; j<n ; j++) {
a[i][j]= sc.nextInt();
}
}
System.out.println("Enter array 2 :-");
for(int i = 0 ; i < n ; i++) {
for(int j = 0 ; j<n ; j++) {
b[j][i]= sc.nextInt();
}
}
int c [][] = new int [n][n];
for(int i = 0 ; i<n ;i++) {
for(int j = 0 ; j<n ; j++) {
c[i][j]= a[i][j]*b[i][j];
}
}
for(int i = 0 ; i<n ; i++) {
for( int j = 0 ; j<n; j++) {
System.out.print(c[i][j] + " ");
}
System.out.println();
}
}
}