import java.util.*;
class Program3
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("enter number of matrix column and row: ");
int c = sc.nextInt();
int r = sc.nextInt();
int arr1[][] = new int[c][r];
int arr2[][] = new int[c][r];
int arr3[][] = new int[c][r];
System.out.println("enter value first matrix: ");
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
arr1[i][j] = sc.nextInt();
}
}
System.out.println("enter value second matrix: ");
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
arr2[i][j] = sc.nextInt();
}
}
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
arr3[i][j] = arr1[i][j] + arr2[i][j];
}
}
System.out.println("\nSum of matrix: ");
for(int i=0; i<c; i++)
{
for(int j=0; j<r; j++)
{
System.out.print(arr3[i][j] + " ");
}
System.out.println("\n");
}
}
}
No comments:
Post a Comment