-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixAdd.java
More file actions
63 lines (62 loc) · 1.5 KB
/
MatrixAdd.java
File metadata and controls
63 lines (62 loc) · 1.5 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
import java.util.Scanner;
public class MatrixAdd
{
public static void main(String ar[])
{
Scanner s = new Scanner(System.in);
int a[][]=new int[2][2];
int b[][]=new int[2][2];
int c[][]=new int[2][2];
int i,j;
System.out.println("Enter first matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
a[i][j]=s.nextInt();
}
}
System.out.println("The First matrix is: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println("");
}
System.out.println("Enter Second Matrix: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
b[i][j]=s.nextInt();
}
}
System.out.println("The Second matrix is: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println("");
}
System.out.println("The Addition of the two matrices is: ");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
System.out.print(c[i][j]+" ");
}
System.out.println("");
}
}
}