SlideShare a Scribd company logo
//Ques. 6 WAP to add two given matrices.

importjava.util.Scanner;
classAddTwoMatrix
{
public static void main(String args[])
{
intm,n,c,d;
Scanner in = new Scanner(System.in);
System.out.print("nEnter the number of rows and columns of matrix = ");
m= in.nextInt();
n= in.nextInt();

int first[][]= new int[m][n];
int second[][]=new int[m][n];
int sum[][]= new int[m][n];

System.out.println("nEnter the elements of first matrix = ");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
first[c][d]= in.nextInt();

System.out.println("nEnter the elements of second matrix = ");
for(c=0;c<m;c++)
for(d=0;d<n;d++)
second[c][d]= in.nextInt();
for(c=0;c<m;c++)
for(d=0;d<n;d++)
{
sum[c][d]= first[c][d] + second[c][d];
}

System.out.println("nSum Of Entered Matrices");
for(c=0;c<2;c++)
{
System.out.print("n");
for(d=0;d<2;d++)
{
System.out.print("t"+sum[c][d]);
}
}
System.out.println();
}
}
OUTPUT:-

More Related Content

TXT
PDF
PDF
Practice programs
TXT
123
PPTX
Cse 121 presentation on matrix [autosaved]
PDF
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
TXT
Operator overloading (binary)
DOCX
WAP to implement inheritance and overloading methods in java
Practice programs
123
Cse 121 presentation on matrix [autosaved]
NCCU: Statistics in the Criminal Justice System, R basics and Simulation - Pr...
Operator overloading (binary)
WAP to implement inheritance and overloading methods in java

What's hot (20)

PDF
Itroroduction to R language
PDF
Matlab lab exe
PPT
16858 memory management2
PDF
Recursion concepts by Divya
PPTX
Lecture 3.2 bt
PDF
Doc 20180130-wa0006
DOCX
two dimensional array
PDF
13. dynamic allocation
PPTX
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
PPTX
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
PPTX
Queue Implementation Using Array & Linked List
PDF
Lecture 3.1 to 3.2 bt
PDF
Stack concepts by Divya
PPTX
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
ODP
Functors, applicatives, monads
PDF
Matlab integration
PPTX
Presentation1 computer shaan
PDF
CS-141 Java programming II ASSIGNMENT 2
PPT
Standard Template Library (STL) in Object Oriented Programming
PDF
Python matplotlib cheat_sheet
Itroroduction to R language
Matlab lab exe
16858 memory management2
Recursion concepts by Divya
Lecture 3.2 bt
Doc 20180130-wa0006
two dimensional array
13. dynamic allocation
2 d array(part 2) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
2 d array(part 1) || 2D ARRAY FUNCTION WRITING || GET 100% MARKS IN CBSE CS
Queue Implementation Using Array & Linked List
Lecture 3.1 to 3.2 bt
Stack concepts by Divya
QUEUE || FUNCTION WRITING BASED ON QUEUE || LINKED LIST || DATA STRUCTURE || ...
Functors, applicatives, monads
Matlab integration
Presentation1 computer shaan
CS-141 Java programming II ASSIGNMENT 2
Standard Template Library (STL) in Object Oriented Programming
Python matplotlib cheat_sheet
Ad

Viewers also liked (6)

PDF
work sample
PPTX
Zanimanja
PDF
PPTX
Higiene y seguridad industrial jairoooo
PPTX
El turismo el la republica dominicana
DOCX
Use of a defensive handgun minnesota statutes
work sample
Zanimanja
Higiene y seguridad industrial jairoooo
El turismo el la republica dominicana
Use of a defensive handgun minnesota statutes
Ad

More from One97 Communications Limited (20)

DOCX
Er. Model Of Hospital Management
DOCX
Fcfs Cpu Scheduling With Gantt Chart
PPTX
Neural Interfacing
PPT
Blue eye technology
PPTX
Computer Forensics
PPTX
Protect Folders without using any Software
PPTX
Introduction to Java Programming
DOCX
WAP to invoke constructors using super keyword in java
DOCX
WAP to find out whether the number is prime or not in java
DOCX
Overriding abstract in java
DOCX
How to achieve multiple inheritances by using interface in java
DOCX
Method overriding in java
DOCX
program on Function overloading in java
DOCX
Program on usage of Final keyword in java
DOCX
WAP to initialize different objects with different values in java
Er. Model Of Hospital Management
Fcfs Cpu Scheduling With Gantt Chart
Neural Interfacing
Blue eye technology
Computer Forensics
Protect Folders without using any Software
Introduction to Java Programming
WAP to invoke constructors using super keyword in java
WAP to find out whether the number is prime or not in java
Overriding abstract in java
How to achieve multiple inheritances by using interface in java
Method overriding in java
program on Function overloading in java
Program on usage of Final keyword in java
WAP to initialize different objects with different values in java

Recently uploaded (20)

PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Computing-Curriculum for Schools in Ghana
PPTX
Lesson notes of climatology university.
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Cell Structure & Organelles in detailed.
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Basic Mud Logging Guide for educational purpose
PDF
Insiders guide to clinical Medicine.pdf
PPTX
master seminar digital applications in india
PDF
TR - Agricultural Crops Production NC III.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Complications of Minimal Access Surgery at WLH
Computing-Curriculum for Schools in Ghana
Lesson notes of climatology university.
FourierSeries-QuestionsWithAnswers(Part-A).pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Cell Structure & Organelles in detailed.
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
GDM (1) (1).pptx small presentation for students
O5-L3 Freight Transport Ops (International) V1.pdf
Sports Quiz easy sports quiz sports quiz
Basic Mud Logging Guide for educational purpose
Insiders guide to clinical Medicine.pdf
master seminar digital applications in india
TR - Agricultural Crops Production NC III.pdf

WAP to add two given matrices in Java

  • 1. //Ques. 6 WAP to add two given matrices. importjava.util.Scanner; classAddTwoMatrix { public static void main(String args[]) { intm,n,c,d; Scanner in = new Scanner(System.in); System.out.print("nEnter the number of rows and columns of matrix = "); m= in.nextInt(); n= in.nextInt(); int first[][]= new int[m][n]; int second[][]=new int[m][n]; int sum[][]= new int[m][n]; System.out.println("nEnter the elements of first matrix = "); for(c=0;c<m;c++) for(d=0;d<n;d++) first[c][d]= in.nextInt(); System.out.println("nEnter the elements of second matrix = "); for(c=0;c<m;c++) for(d=0;d<n;d++) second[c][d]= in.nextInt();
  • 2. for(c=0;c<m;c++) for(d=0;d<n;d++) { sum[c][d]= first[c][d] + second[c][d]; } System.out.println("nSum Of Entered Matrices"); for(c=0;c<2;c++) { System.out.print("n"); for(d=0;d<2;d++) { System.out.print("t"+sum[c][d]); } } System.out.println(); } }