Write a program to perform 3X3 matrix addition.

class MatrixAdd
{
 public static void main(String arg[])
 {
  int a[][]= new int[3][3];
  int b[][] = new int[3][3];
  int c[][]= new int[3][3];
  int i,j,k=0;
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
   {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    a[i][j]=k;
     k++;
    b[i][j]=k;
   }
  }
  System.out.println("1st mat. is");
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     System.out.print("  " +a[i][j]);
    }
     System.out.println("\n");
   }
   System.out.println("2nd mat. is");
  for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     System.out.print("  " +b[i][j]);
    }
     System.out.println("\n");
   }
  System.out.println("addtn is");
 for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
   {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   
    c[i][j]=a[i][j]+b[i][j];
   }
  }
   for(i=0;i<3;i++)
  {
   for(j=0;j<3;j++)
    {
     System.out.print("  " +c[i][j]);
    }
     System.out.println("\n");
   }
 }
}

4 comments:

  1. Very simple and nice way to understand this java program for "Two and Multi-dimensional array" or 3x3 matrix.

    ReplyDelete
  2. i want 3X3 matrix multiplication program in java

    ReplyDelete
  3. They conjointly watch nfl games online found out their gift kind when prying Associate in Nursing {evolutionary|organic method|biological process} process like what befell on earth. Their social organization and activity traits square measure unthinkably totally different from those of the folks on earth.

    ReplyDelete
  4. i want this program with output

    ReplyDelete