-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmatrixmulti.java
54 lines (53 loc) · 1.22 KB
/
matrixmulti.java
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
//write a java program to multiply of two matrix
import java.util.Scanner;
class matrixmulti {
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a[][]=new int[2][2];
int b[][]=new int[2][2];
int c[][]=new int[2][2];
int j,k,l,i;
System.out.println("enter first matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("enter second matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
b[i][j]=sc.nextInt();
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=0;
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
for(k=0;k<2;k++)
{
c[i][j]+=a[i][k]*b[k][j];
}
}
}
System.out.print("resultant matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.println(c[i][j]+ " ");
}
}
}
}