Google Search

Monday, October 10, 2011

Java program for the multiplications of two array program


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.println("enter no of rows");
int m=Integer.parseInt(br.readLine());
System.out.println("enter no of columns");
int n=Integer.parseInt(br.readLine());
int a[][]=new int[m][n];
int i,j,k;
System.out.println("enter the elements");
{
for( i=0;i<m;i++)
{
for(j=0;j<n;j++)
{


a[i][j]=Integer.parseInt(br.readLine());
}
}
System.out.println("enter no of rows");
int p=Integer.parseInt(br.readLine());
System.out.println("enter no of columns");
int q=Integer.parseInt(br.readLine());
int b[][]=new int[p][q];
System.out.println("enter the elements");
{
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)
System.out.println("the mulptiplied matrix is");
{
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]);
}
}
}
}
}
}

0 comments:

Post a Comment