// Program
import
java.util.Scanner;
public
class Matrix_Addition
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[10][10];
int b[][]=new int[10][10];
System.out.println("Rows");
int r=sc.nextInt();
System.out.println("Columns");
int c=sc.nextInt();
System.out.println("Enter elements
for 1st Matrix");
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("First Matrix
is");
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
System.out.print("\t"+a[i][j]);
}
System.out.print("\n");
}
System.out.println("Enter elements for
2nd Matrix");
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
b[i][j]=sc.nextInt();
}
}
System.out.println("Second Matrix
is");
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
System.out.print("\t"+b[i][j]);
}
System.out.print("\n");
}
System.out.println("After Addition
the matrix is");
for(int i=1;i<=r;i++)
{
for(int j=1;j<=c;j++)
{
System.out.print("\t"+(a[i][j]+b[i][j]));
}
System.out.print("\n");
}
}
}
No comments:
Post a Comment
Note: only a member of this blog may post a comment.