forked from SoumyadeepMukherjee/Matrix_Manipulation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MatAdd.java
67 lines (67 loc) · 1.37 KB
/
MatAdd.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
import java.util.*;
public class MatAdd
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Number of Rows in the Matrix");
int n=sc.nextInt();
System.out.println("Enter the Number of Columns in the Matrix");
int m=sc.nextInt();
int a[][]=new int[n][m];
int b[][]=new int[n][m];
int c[][]=new int[n][m];
System.out.println("Enter Values in the First Matrix");
for(int i=0;i<n;i++)
{
System.out.println("Enter Values in Row "+(i+1));
for(int j=0;j<m;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("Enter Values in the Second Matrix");
for(int i=0;i<n;i++)
{
System.out.println("Enter Values in Row "+(i+1));
for(int j=0;j<m;j++)
{
b[i][j]=sc.nextInt();
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println(" ");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(b[i][j]+" ");
}
System.out.println();
}
System.out.println(" ");
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
System.out.print(c[i][j]+" ");
}
System.out.println();
}
System.out.println(" ");
}
}