/**
* class matrixMultiple finds the mutiplication of two matirces.
*
* @author: Nitendra Verma
* @version: Sept 11, 2013
*/
import java.util.Scanner;
public class matrixMultiple
{
public static void main()
{
int row,col1,col2;
Scanner in=new Scanner(System.in);
System.out.println("Enetr number of rows");
row=in.nextInt();
System.out.println("Enetr number of columns of first matrix");
col1=in.nextInt();
System.out.println("Enetr number of columns of second matrix");
col2=in.nextInt();
int[][] first=new int[row][col1];
int[][] second=new int[row][col2];
int[][] third=new int[row][col1];
System.out.println("Enetr "+row*col1 +" elements of first matrix");
for(int i=0;i<row;i++)
{
for(int j=0;j<col1;j++)
{
first[i][j]=in.nextInt();
}
}
System.out.println("Enetr "+row*col2 +"elements of second matrix");
for(int i=0;i<row;i++)
{
for(int j=0;j<col2;j++)
{
second[i][j]=in.nextInt();
}
}
int sum=0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col2;j++)
{
for(int k=0;k<col1;k++)
{
sum+=first[i][k]*second[k][j];
}
third[i][j]=sum;
sum=0;
}
}
System.out.println("Product of above matrices");
for(int i=0;i<row;i++)
{
for(int j=0;j<col1;j++)
{
System.out.print(third[i][j]+"\t");
}
System.out.println();
}
}
}
/*---------------Program developed by: Nitendra Verma---------------*/
//For more details visit http://javawithnitendra.blogspot.in
* class matrixMultiple finds the mutiplication of two matirces.
*
* @author: Nitendra Verma
* @version: Sept 11, 2013
*/
import java.util.Scanner;
public class matrixMultiple
{
public static void main()
{
int row,col1,col2;
Scanner in=new Scanner(System.in);
System.out.println("Enetr number of rows");
row=in.nextInt();
System.out.println("Enetr number of columns of first matrix");
col1=in.nextInt();
System.out.println("Enetr number of columns of second matrix");
col2=in.nextInt();
int[][] first=new int[row][col1];
int[][] second=new int[row][col2];
int[][] third=new int[row][col1];
System.out.println("Enetr "+row*col1 +" elements of first matrix");
for(int i=0;i<row;i++)
{
for(int j=0;j<col1;j++)
{
first[i][j]=in.nextInt();
}
}
System.out.println("Enetr "+row*col2 +"elements of second matrix");
for(int i=0;i<row;i++)
{
for(int j=0;j<col2;j++)
{
second[i][j]=in.nextInt();
}
}
int sum=0;
for(int i=0;i<row;i++)
{
for(int j=0;j<col2;j++)
{
for(int k=0;k<col1;k++)
{
sum+=first[i][k]*second[k][j];
}
third[i][j]=sum;
sum=0;
}
}
System.out.println("Product of above matrices");
for(int i=0;i<row;i++)
{
for(int j=0;j<col1;j++)
{
System.out.print(third[i][j]+"\t");
}
System.out.println();
}
}
}
/*---------------Program developed by: Nitendra Verma---------------*/
//For more details visit http://javawithnitendra.blogspot.in
No comments:
Post a Comment
Ur comments r most welcome...