Jump to content

sakshijn

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by sakshijn

  1. // *To perform matrix multiplication, the first matrix must have the same number of columns as the second matrix has rows. public class MatrixMultiplicationExample{ public static void main(String args[]){ //matrix 1 int a[][]={{1,1,1},{2,2,2},{3,3,3}}; //matrix 2 int b[][]={{1,1,1},{2,2,2},{3,3,3}}; //creating another matrix to store the multiplication of two matrices int c[][]=new int[3][3]; //3 rows and 3 columns //multiplying and printing multiplication of 2 matrices for(int i=0;i<3;i++){ for(int j=0;j<3;j++){ c[i][j]=0; for(int k=0;k<3;k++) { c[i][j]+=a[i][k]*b[k][j]; }//end of k loop System.out.print(c[i][j]+" "); //printing matrix element }//end of j loop System.out.println(); } }} // Hope it will help you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.