About Me

My photo
Raipur, Chhattisgarh, India
Hi , I am Amit Thakur. I have worked as a QA Engineer for two years and as a Java Developer for one year in NIHILENT TECHNOLOGIES PVT. LTD., Pune.Currently I am working as DEAN (Research & Development) in Bhilai Institute of Technology, Raipur.

Monday, April 19, 2010

JAVA(Multiplication of Two Matrix A anb B)--------------------------

//Multiplication of Two Matrix A anb B


import java.io.*;


class Matrix

{

public static void main(String dd[])

{

int A[][]=new int[3][3];

int B[][]=new int[3][3];

int C[][]=new int[3][3];



try

{

DataInputStream dis=new DataInputStream(System.in);

System.out.println("Enter Elements in Matrix A...");

for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

A[i][j]=Integer.parseInt(dis.readLine());

}

}





System.out.println("Enter Elements in Matrix B...");

for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

B[i][j]=Integer.parseInt(dis.readLine());

}

}

}

catch(Exception e){}



System.out.println("Multiplication of Matrix A and B is...");



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]+C[i][j];

}

}

}



for(int i=0;i<3;i++)

{

for(int j=0;j<3;j++)

{

System.out.print(" "+C[i][j]);

}

System.out.println("");

}



}

}

No comments: