0% found this document useful (0 votes)
5 views

Program 18

Uploaded by

Jaainam Jain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Program 18

Uploaded by

Jaainam Jain
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Program 18 Matrix addition

1 3 4 1 3 4
Matrix 1 2 4 3 Matrix 2 2 4 3
3 4 5 1 2 4

Matrix 1 1+1 3+3 4+4


+ 2+2 4+4 3+3
Matrix2 3+1 4+2 5+4

Matrix 1 2 6 8
+ 4 8 6
Matrix2 4 6 9
import java.util.*;
class Matrix_addition
{
public static void main()
{
Scanner sc=new Scanner(System.in);
int a[][]=new int[3][3];
int b[][]=new int[3][3];
int c[][]=new int[3][3];
int i,j,k;
System.out.println(“Enter the elements of first matrix”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(“Enter any number:”);
a[i][j]=sc.nextInt();
}
}
System.out.println(“Enter the elements of Second matrix”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(“Enter any number:”);
b[i][j]=sc.nextInt();
}
}
int sum=0;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
System.out.println(“Matrix first element”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(a[i][j]+”\t”);
}
System.out.println();
}
System.out.println(“Matrix second element”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(b[i][j]+”\t”);
}
System.out.println();
}
System.out.println(“Resultant Matrix”);
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
System.out.print(c[i][j]+”\t”);
}
System.out.println();
}
}
}

You might also like