-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrixaddition.java
More file actions
45 lines (45 loc) · 1.1 KB
/
matrixaddition.java
File metadata and controls
45 lines (45 loc) · 1.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
import java.util.Scanner;
class matrixaddition
{
public static void main(String[] args)
{
System.out.println("Enter the size of rows and columns of the array");
int sizeofrow=new Scanner(System.in).nextInt();
int sizeofcol=new Scanner(System.in).nextInt();
int a[][]=new int [sizeofrow][sizeofcol];
int b[][]=new int [sizeofrow][sizeofcol];
int c[][]=new int [sizeofrow][sizeofcol];
System.out.println("Enter array elements");
for(int row=0;row<sizeofrow;row++)
{
for (int col=0;col<sizeofcol;col++)
{
a[row][col]=new Scanner(System.in).nextInt();
}
}
System.out.println("Enter next array elements");
for(int row=0;row<sizeofrow;row++)
{
for (int col=0;col<sizeofcol;col++)
{
b[row][col]=new Scanner(System.in).nextInt();
}
}
for(int row=0;row<sizeofrow;row++)
{
for (int col=0;col<sizeofcol;col++)
{
c[row][col]=a[row][col]+b[row][col];
}
}
System.out.println("Matrix elements are");
for(int row=0;row<sizeofrow;row++)
{
for (int col=0;col<sizeofcol;col++)
{
System.out.print(c[row][col]);
}
System.out.println();
}
}
}