Custom Search

Saturday, 25 August 2012

Java Program for Matrix Multiplication, Write a program in java language for Matrix Multiplication


Java Program for  Matrix Multiplication, Write a program in java language for Matrix Multiplication

Program
class multi
{
public static void main(String args[])
{
int k=1;
int arr[][],arr2[][],arr3[][];

arr= new int[3][3];
arr2=new int[3][3];
arr3=new int[3][3];

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
arr[i][j]=k;
arr2[i][j]=++k;
k++;
}

}
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
for(int p=0;p<3;p++)
{
arr3[i][j]+=arr[i][p]*arr2[p][j];
}

}
}

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr[i][j]);
}
System.out.println();

}
System.out.println();
System.out.println();

for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr2[i][j]);
}
System.out.println();
}
System.out.println();
System.out.println();
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(" "+arr3[i][j]);
}
System.out.println();
}
}
}

No comments:

Post a Comment

Laptops