answersLogoWhite

0

//Matrix multiplication import java.util.Scanner; public class Matrix

{

public static void main(String args[])

{

Scanner s= new Scanner(System.in);

int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

a[i][j]=s.nextInt();

}

}//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=s.nextInt();

}

}//end of b matrix System.out.println("the result matrix is:");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

for(k=0;k<n;k++)

{ c[i][j]+=a[i][k]*b[k][j]; }

}

} for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

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

}System.out.println();

}

}//end of main

}//end of class

User Avatar

Wiki User

15y ago

Still curious? Ask our experts.

Chat with our AI personalities

SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
EzraEzra
Faith is not about having all the answers, but learning to ask the right questions.
Chat with Ezra
More answers

class Array58

{

public static void main(String[] args)

{

int i,j,k;

int [][] a={{1,2,3},{4,5,6},{7,8,9}};

int [][] b={{9,8,7},{6,5,4},{3,2,1}};

int [][]c=new int[3][3];

for (i=0;i<a.length;i++)

{

for (j=0;j<a[i].length;j++)

{

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

}

System.out.println(" ");

}

System.out.println(" ");

for (i=0;i<b.length;i++ )

{

for (j=0;j<b[i].length;j++)

{

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

}

System.out.println(" ");

}

System.out.println(" ");

for(i=0;i<a.length;i++)

{

for(j=0;j<b.length;j++)

{

c[i][j]=0;

for(k=0;k<a.length;k++)

{

c[i][j]+=a[i][k]*b[k][j];

}

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

}

System.out.println(" ");

}

}

}

Shashi 8010234944

User Avatar

Wiki User

14y ago
User Avatar

import java.util.Scanner; public class Matrix

{

public static void main(String args[])

{

Scanner s= new Scanner(System.in);

int i,j,k; System.out.println("enter the value of n"); int n=s.nextInt(); int a[][]=new int[n][n]; int b[][]=new int[n][n]; int c[][]=new int[n][n]; System.out.println("enter the array elements of a:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

a[i][j]=s.nextInt();

}

}//end of a matrix System.out.println("enter the array elements of b:"); for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

b[i][j]=s.nextInt();

}

}//end of b matrix System.out.println("the result matrix is:");

for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

for(k=0;k<n;k++)

{ c[i][j]+=a[i][k]*b[k][j]; }

}

} for(i=0;i<n;i++)

{

for(j=0;j<n;j++)

{

System.out.println(+c[i][j]);

}

}

}//end of main

}//end of class

User Avatar

Wiki User

15y ago
User Avatar

import java.io.*;

public class matrixmul

{

public static void main (String args[])

{

try

{

BufferedReader e = new BufferedReader(new InputStreamReader(System.in));

int m,n;

int c[][] = new int[3][3];

int b[][] = new int[3][3];

int d[][] = new int[3][3];

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

System.out.println("-- Enter A number in row# "+(m+1)+" & # "+(n+1)+" column --" );

c[m][n] = Integer.parseInt(e.readLine());

}

}

System.out.println(" ----- First Matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(c[m][n]);

}

System.out.println();

}

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

System.out.println("-- Enter A number in row# "+(m+1)+" & # "+(n+1)+" column --" );

b[m][n] = Integer.parseInt(e.readLine());

}

}

System.out.println(" ----- Second Matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(c[m][n]);

}

System.out.println();

}

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ;n++)

{

d[m][n] = d[m][n]+(b[m][n]*c[m][n]);

}

}

System.out.println(" ----- Multiplication of above matrix ----");

for ( m = 0 ; m < 3; m++ )

{

for (n = 0; n < 3 ; n++)

{

System.out.print(" "+d[m][n]);

}

System.out.println();

}

}

catch (Exception e){}

}

}

User Avatar

Wiki User

12y ago
User Avatar

Matrix Add

/* Program MAT_ADD.C
**
** Illustrates how to add two 3X3 matrices.
**
** Peter H. Anderson, Feb 21, '97
*/

#include <stdio.h>

void add_matrices(int a[][3], int b[][3], int result[][3]);
void print_matrix(int a[][3]);

void main(void)
{
int p[3][3] = { {1, 3, -4}, {1, 1, -2}, {-1, -2, 5} };
int q[3][3] = { {8, 3, 0}, {3, 10, 2}, {0, 2, 6} };
int r[3][3];

add_matrices(p, q, r);

printf("\nMatrix 1:\n");
print_matrix(p);

printf("\nMatrix 2:\n");
print_matrix(q);

printf("\nResult:\n");
print_matrix(r);
}

void add_matrices(int a[][3], int b[][3], int result[][3])
{
int i, j;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
result[i][j] = a[i][j] + b[i][j];
}
}
}

void print_matrix(int a[][3])
{
int i, j;
for (i=0; i<3; i++)
{
for (j=0; j<3; j++)
{
printf("%d\t", a[i][j]);
}
printf("\n");
}
}

User Avatar

Wiki User

15y ago
User Avatar

import java.io.*;

class mat

{

protected static void main()throws IOException

{

BufferedReader in=new BufferedReader(new InputStreamReader());

int a[][]=new int[10][10];

int b[][]=new int[10][10];

int c[][]=new int[10][10];

for(byte i=0;i<10;i++)

{

for(byte j=0;j<10;j++)

{

System.out.print("Enter the value of a[ "+i+" ][ "+j+"]: ");

a[i][j]=Integer.parseInt(in.readLine());

}

}

for(byte i=0;i<10;i++)

{

for(byte j=0;j<10;j++)

{

System.out.print("Enter the value of b["+i+" ][ "+j+" ]: ");

b[i][j]=Integer.parseInt(in.readLine());

c[i][j]=a[i][j]+b[i][j];

}

}

for(byte i=0;i<10;i++)

{

System.out.println();

for(byte j=0;j<10;j++)

{

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

}

}

User Avatar

Wiki User

15y ago
User Avatar

write a program of two matrices and show row and column wise

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: Write a program for Multiplication of two matrices in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp