Write a Java program to multiply two given matrices. - Code

Latest

programs

Monday, October 10, 2011

Write a Java program to multiply two given matrices.



Write a Java program to multiply two given matrices.
import java.lang.*;
import java.io.*;
class arraymul


{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("enter no of rows");
int m=Integer.parseInt(br.readLine());
System.out.print("enter no of columns");
int n=Integer.parseInt(br.readLine());
int a[][]=new int[m][n];
int i,j,k;
{
for( i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.print("enter no of rows");
int p=Integer.parseInt(br.readLine());
System.out.print("enter no of columns");
int q=Integer.parseInt(br.readLine());
int b[][]=new int[p][q];
{
for( i=0;i<p;i++)
{
for( j=0;j<q;j++)
{
b[i][j]=Integer.parseInt(br.readLine());
}
}


}
int c[][]=new int[m][i];
if(n==p)
{
for( i=0;i<m;i++)
{
for( j=0;j<q;j++)
{
c[i][j]=0;
for( k=0;k<p;k++)
{
c[i][j]=c[i][j]+(a[i][k]*b[k][j]);
}
}
}
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
System.out.println(c[i][j]);
}
}
}
}
} } .

5 comments:

  1. The purpose: to help break the isolation and boost the morale of detainees, who may be held for months before being released or deported.
    marketing dissertation topics

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. Its a very useful post. Please take care of the indentation it would make the program look good and cleaner.
    Check this out : Best Way To Learn Java Programming

    ReplyDelete