package pl;
import java.util.Scanner;
/**
*
* @author Kanu
*/
public class Pl {
public static void main(String[] args) {
int m,n;
System.out.print("Enter rows and columns : ");
Scanner in = new Scanner(System.in);
m = in.nextInt();
n = in.nextInt();
System.out.println("Enter data for array 1:");
int [][]a=new int[m][n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++){
System.out.print("Enter Num :");
a[i][j]=in.nextInt();
}
}
System.out.println("Enter data for array 2:");
int [][]b=new int[m][n];
for(int i=0;i<m;i++)
{
for(int j=0;j<n;j++){
System.out.print("Enter Num :");
b[i][j]=in.nextInt();
}
}
int [][]c=new int[m][n];
for(int i =0;i<m;i++)
{
for(int j =0;j<n;j++){
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println("Array 1 is :");
for(int i =0;i<m;i++)
{
for(int j =0;j<n;j++){
System.out.print(a[i][j]+"");
}System.out.println();
}
System.out.println("Array 2 is :");
for(int i =0;i<m;i++)
{
for(int j =0;j<n;j++){
System.out.print(b[i][j]+"");
}System.out.println();
}
System.out.println("sum of two array is :");
for(int i =0;i<m;i++)
{
for(int j =0;j<n;j++){
System.out.print(c[i][j]+"");
}System.out.println();
}
}
}
output:
Enter rows and columns : 2
2
Enter data for array 1:
Enter Num :1
Enter Num :2
Enter Num :3
Enter Num :4
Enter data for array 1:
Enter Num :1
Enter Num :2
Enter Num :3
Enter Num :4
Array 1 is :
12
34
Array 2 is :
12
34
sum of two array is :
24
68
No comments:
Post a Comment