-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix.java
More file actions
62 lines (52 loc) · 1 KB
/
matrix.java
File metadata and controls
62 lines (52 loc) · 1 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
import java.util.*;
class matrix
{
public static void main(String args[])
{
int a[][],b[][],c[][],i,j,k;
a=new int [3][3];
b=new int [3][3];
c=new int [3][3];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the first matrix:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
a[i][j]=sc.nextInt();
System.out.println("Enter the second matrix:");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
b[i][j]=sc.nextInt();
System.out.println("matrix addition");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
System.out.println("matrix multiplication");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
for(k=0;k<3;k++)
{
c[i][j]=0;
c[i][j]+=a[i][j]*b[i][j];
}
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
System.out.print(c[i][j]+"\t");
}
System.out.println();
}
}
}