Tuesday, 12 March 2013

Java Program To Multiply Two Given Matrices


/* Java Program To Multiply Two Given Matrices*/
// File Name: matmult.java



import java.io.*;
class matmult {
public static void main(String args[])throws IOException{
int a[][]={{1,2,3},{4,5,6},{7,8,9}};
int b[][]={{1,2,3},{4,5,6},{7,8,9}};
int c[][],i,j,k;
c=new int[3][3];
for(i=0;i<=2;i++){
for(j=0;j<=2;j++){
for(k=0;k<=2;k++){
c[i][j]+=a[i][k]*b[k][j];
}

}

}
System.out.println("Matrix Multiplication");
for(i=0;i<=2;i++){
for(j=0;j<=2;j++){
System.out.print(c[i][j]+"\t");
}
System.out.print("\n");
}
System.out.println("www.shashanktechmologies.blogspot.com");
}
}


OUTPUT:

COMPILATION: G:\shashank>javac matmult.java

INTERPRETATION: G:\shashank>java matmult




No comments:

Post a Comment