-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatric_Multiplication.java
More file actions
55 lines (53 loc) · 1.26 KB
/
Copy pathMatric_Multiplication.java
File metadata and controls
55 lines (53 loc) · 1.26 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
//Java program to find the productof two Matrix
import java.util.Scanner;
class Matric_Multiplication{
public static void main(String args[]){
int r1,r2,c1,c2,i,j,k;
int a[][] =new int[50][50];
int b[][] =new int[50][50];
int c[][] =new int[50][50];
Scanner sc =new Scanner(System.in);
System.out.print("Enter the Order of first Matrix : ");
r1 =sc.nextInt();
c1 =sc.nextInt();
System.out.print("Enter the Order of second Matrix : ");
r2 =sc.nextInt();
c2 =sc.nextInt();
if(c1==r2)
{
System.out.println("Enter Elements of first Matrix : ");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
{
a[i][j]=sc.nextInt();
}
System.out.println("Enter Elements of second Matrix : ");
for(i=0;i<r1;i++)
for(j=0;j<c1;j++)
{
b[i][j]=sc.nextInt();
}
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
{
c[i][j]=0;
for(k=0;k<c1;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
System.out.println("Products : ");
for(i=0;i<r1;i++)
{
for(j=0;j<c2;j++)
{
System.out.print("\t"+c[i][j]);
}
System.out.print("\n");
}
sc.close();
}
else
System.out.println("Multiplication is not possible!");
}
}