Java Program to multiply two matrices – Q9
Q9: Java Program to multiply two matrices
class matrix_mul{ public static void main(String args[]){ int mat1[][] = { {1,2,3}, {4,5,6}, {7,8,9} }; int mat2[][] = { {9,8,7}, {6,5,4}, {3,2,1} }; int tot[][] = new int[3][3]; int i, j, k; for(i=0; i<3; i++){ for(j=0; j<3; j++){ tot[i][j] = 0; for(k=0; k<3; k++){ tot[i][j] = tot[i][j] + (mat1[i][k] * mat2[k][j]); } } } for(i=0; i<3; i++){ for(j=0; j<3; j++){ System.out.print(" " + tot[i][j]); } System.out.println(); } } }
… from College notes (BCA/MCA assignments):
Categories: Java
Java Basic Programs, Multiply Matrix Program
Comments (0)
Trackbacks (0)
Leave a comment
Trackback