-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.java
90 lines (80 loc) · 1.88 KB
/
Matrix.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String args[])
{
int a[][]=new int[10][10];
int b[][]=new int[10][10];
int c[][]=new int[20][20];
int m1,m2,n1,n2;
int i,j,k;
Scanner sc=new Scanner(System.in);
// void read()
// {
// Scanner sc=new Scanner(System.in);
// int i,int j;
// int k=1;
//
// System.out.println("enter the row and colom of"+ k +"matrix");
// int m=sc.nextInt();
// int n=sc.nextInt();
// for(i=0;i<m;i++) {
// for(j=0;j<n;j++) {
// a[i][j]=sc.nextInt();
// }
// }
// }
System.out.println("For the first matrix");
System.out.println("enter the row and colom of first matrix");
m1=sc.nextInt();
n1=sc.nextInt();
System.out.println("row elements");
for(i=0;i<m1;i++) {
for(j=0;j<n1;j++) {
System.out.println("["+i+"]"+"["+j+"}");
a[i][j]=sc.nextInt();
}}
System.out.println("Entred firt matrix is: ");
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("For the second matrix");
System.out.println("enter the row and colom of second matrix");
m2=sc.nextInt();
n2=sc.nextInt();
System.out.println("row elements");
for(i=0;i<m2;i++) {
for(j=0;j<n2;j++) {
System.out.println("["+i+"]"+"["+j+"}");
b[i][j]=sc.nextInt();
}
}
System.out.println("Entred second matrix is: ");
for(i=0;i<m1;i++)
{
for(j=0;j<n1;j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
int multi=0;
for(i=0;i<m1;i++) {
for(j=0;j<n2;j++) {
for(k=0;k<m2;k++) {
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
//c[i][j]=multi;
}
}
System.out.println("the multiplied matrix");
for(i=0;i<m1;i++) {
for(j=0;j<n2;j++) {
System.out.print(c[i][j]+" ");
}
System.out.println();
}
}}