Addition of two matrix

Addition of two matrix

Addition of two matrix
class test
{
public static void main(String args[])
{
int a[][]={{1,2,3},{4,5,6},{7,8,9}};
int b[][]={{1,2,3},{4,5,6},{7,8,9}};
int c[][]=new int[3][3];
System.out.println(“Addition of two matrix is”);
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
c[i][j]=a[i][j]+b[i][j];
System.out.print(c[i][j]+” “);
}
System.out.println();
}
}
}

Output:
Addition of two matrix is
2 4 6
8 10 12
14 16 18

Leave a Reply

Your email address will not be published. Required fields are marked *