PROGRAM TO PERFORM ADDITION OF TWO MATRICES

//PROGRAM TO PERFORM ADDITION OF TWO MATRICES
class addmatrix
{
int a[ ][ ]={{1,2,3,4},{4,5,6,7}};
int b[ ][ ]={{0,4,7,2},{6,1,8,3}};
int c[ ][ ]={{0,0,0,0},{0,0,0,0}},i,j;
void  add( )
{
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void output( )
{
System.out.println(“Addition of two matrices is: ” );
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{

System.out.print(”         “+c[i][j] );
}
System.out.println( );
}
}
}
class Test
{
public static void main(String args[ ])
{
addmatrix s=new addmatrix( );
s.add();
s.output();
}
}

Leave a Reply

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