-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.java
More file actions
49 lines (42 loc) · 860 Bytes
/
Matrix.java
File metadata and controls
49 lines (42 loc) · 860 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
38
39
40
41
42
43
44
45
46
47
48
import java.io.*;
class Matrix {
static int N = 4;
static void multiply(int mat1[][],
int mat2[][], int res[][])
{
int i, j, k;
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
{
res[i][j] = 0;
for (k = 0; k < N; k++)
res[i][j] += mat1[i][k]
* mat2[k][j];
}
}
}
public static void main (String[] args)
{
int mat1[][] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}};
int mat2[][] = { {1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3},
{4, 4, 4, 4}};
int res[][] = new int[N][N] ;
int i, j;
multiply(mat1, mat2, res);
System.out.println("Result matrix"
+ " is ");
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
System.out.print( res[i][j]
+ " ");
System.out.println();
}
}
}