-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultmat.java
66 lines (60 loc) · 1.63 KB
/
multmat.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
55
56
57
58
59
60
61
62
63
64
65
66
import java.util.*;
class multmat
{
public static void main(String args[])
{
int a[][] = new int[10][10];
int b[][] = new int[10][10];
int c[][] = new int[10][10];
Scanner obj = new Scanner(System.in);
System.out.println("how many row in martix a");
int r1 = obj.nextInt();
System.out.println("how many coln in matrix a");
int c1 = obj.nextInt();
System.out.println("how many row in b");
int r2 = obj.nextInt();
System.out.println("how many coln in b");
int c2 = obj.nextInt();
if(r1==c2)
{
System.out.println("enter the elements into the array a");
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
a[i][j] = obj.nextInt();
System.out.println("enter the elements into the array b");
for(int i=0;i<r1;i++)
for(int j=0;j<c1;j++)
b[i][j] = obj.nextInt();
System.out.println("matrix a");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(a[i][j]+" ");
}
System.out.println("matrix b");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(b[i][j]+" ");
}
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] =c[i][j]+a[k][j]*b[i][k];
}
System.out.println("matrix a*b");
for(int i=0;i<r1;i++)
{
System.out.println();
for(int j=0;j<c1;j++)
System.out.print(c[i][j]+" ");
}
}
else
System.out.println("multi is not possible");
}
}