-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductmatrix.java
More file actions
81 lines (79 loc) · 2.29 KB
/
productmatrix.java
File metadata and controls
81 lines (79 loc) · 2.29 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import java.util.*;
class productmatrix
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter the order of first matrix");
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println("enter the order of second matrix");
int c=sc.nextInt();
int d=sc.nextInt();
int e[][]=new int[a][b];
int f[][]=new int[c][d];
if(b==c)
{
System.out.println("enter the elements of first matrix");
for(int i=0;i<a;i++)
{
for(int j=0;j<b;j++)
{
e[i][j]=sc.nextInt();
}
}
System.out.println("enter the elements of second matrix");
for(int i=0;i<c;i++)
{
for(int j=0;j<d;j++)
{
f[i][j]=sc.nextInt();
}
}
System.out.println();
for(int i=0;i<a;i++)
{
System.out.println();
for(int j=0;j<b;j++)
{
System.out.println(e[i][j]+"\t");
System.out.println(" ");
}
}
System.out.println();
for(int i=0;i<c;i++)
{
System.out.println();
for(int j=0;j<d;j++)
{
System.out.println(f[i][j]+"\t");
}
System.out.println(" ");
}
int g[][]=new int[a][d];
for(int i=0;i<a;i++)
{
for(int j=0;j<d;j++)
{
for(int k=0;k<b;k++)
{
g[i][j]+=e[i][k]*f[k][j];
}
}
}
System.out.println();
System.out.println("the product of matrix is :");
for(int i=0;i<a;i++)
{
for(int j=0;j<d;j++)
{
System.out.println(g[i][j]+"\t");
System.out.println(" ");
}
}
}
else
{
System.out.println("mulltiplication not possible");
}
}
}