-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd_Two_Matrix.java
More file actions
44 lines (32 loc) · 941 Bytes
/
Copy pathAdd_Two_Matrix.java
File metadata and controls
44 lines (32 loc) · 941 Bytes
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
import java.util.Scanner;
class Add_Two_Matrix
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the number of Row and Columns of Matrix");
int m = in.nextInt();
int n = in.nextInt();
int first [] [] = new int [m][n];
int second [] [] = new int [m][n];
int sum [] [] = new int [m][n];
System. out .print("Enter the elemnt of first matrix");
for (int c=0;c<m ;c++ )
for (int d =0;d<n ;d++ )
first [c][d]= in.nextInt();
System. out .print("Enter the elemnt of Second matrix");
for (int c =0;c<m ;c++ )
for (int d=0;d<n ;d++ )
second [c][d]=in.nextInt();
for (int c=0;c<m ;c++ )
for (int d= 0;d<n ;d++ )
sum [c] [d]= first [c][d] + second [c][d];
System.out.println("Sum of Entered Matrix :-");
for (int c=0;c<m ;c++ )
{
for (int d=0;d<n ;d++ )
System.out.print(sum [c][d] +" ");
System.out.println();
}
}
}