SlideShare a Scribd company logo
1 of 1
Download to read offline
import java.util.Scanner; class AddTwoMatrix { public static void main(String args[]) {
int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println("Enter 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("Enter 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("Enter 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]; //replace '+' with '-' to subtract matrices
System.out.println("Sum of entered matrices:-"); for ( c = 0 ; c < m ; c++ ) { for (
d = 0 ; d < n ; d++ ) System.out.print(sum[c][d]+"t"); System.out.println(); }
} }
Solution
import java.util.Scanner; class AddTwoMatrix { public static void main(String args[]) {
int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println("Enter 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("Enter 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("Enter 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]; //replace '+' with '-' to subtract matrices
System.out.println("Sum of entered matrices:-"); for ( c = 0 ; c < m ; c++ ) { for (
d = 0 ; d < n ; d++ ) System.out.print(sum[c][d]+"t"); System.out.println(); }
} }

More Related Content

Similar to import java.util.Scanner; class AddTwoMatrix { public static vo.pdf

JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfRohitkumarYadav80
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdfangelsfashion1
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdfanupamfootwear
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docxKatecate1
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...Nithin Kumar,VVCE, Mysuru
 
import java.util.; public class ClientMerge_2 {     static Scan.pdf
import java.util.; public class ClientMerge_2 {     static Scan.pdfimport java.util.; public class ClientMerge_2 {     static Scan.pdf
import java.util.; public class ClientMerge_2 {     static Scan.pdfpremkhatri99
 
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfJava Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfirshadoptical
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Kanis Fatema Shanta
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdfAnkitchhabra28
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iiiNiraj Bharambe
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 

Similar to import java.util.Scanner; class AddTwoMatrix { public static vo.pdf (20)

JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
import java.util.Scanner;public class ArrayOperation {    inp.pdf
import java.util.Scanner;public class ArrayOperation {     inp.pdfimport java.util.Scanner;public class ArrayOperation {     inp.pdf
import java.util.Scanner;public class ArrayOperation {    inp.pdf
 
Oot practical
Oot practicalOot practical
Oot practical
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
Ann
AnnAnn
Ann
 
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 Problem1 java codeimport java.util.Scanner; Java code to pr.pdf Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
Problem1 java codeimport java.util.Scanner; Java code to pr.pdf
 
.net progrmming part2
.net progrmming part2.net progrmming part2
.net progrmming part2
 
import java.uti-WPS Office.docx
import java.uti-WPS Office.docximport java.uti-WPS Office.docx
import java.uti-WPS Office.docx
 
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
VTU Design and Analysis of Algorithms(DAA) Lab Manual by Nithin, VVCE, Mysuru...
 
C++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLESC++ ARRAY WITH EXAMPLES
C++ ARRAY WITH EXAMPLES
 
import java.util.; public class ClientMerge_2 {     static Scan.pdf
import java.util.; public class ClientMerge_2 {     static Scan.pdfimport java.util.; public class ClientMerge_2 {     static Scan.pdf
import java.util.; public class ClientMerge_2 {     static Scan.pdf
 
Java Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdfJava Assignment.Implement a binary search algorithm on an array..pdf
Java Assignment.Implement a binary search algorithm on an array..pdf
 
Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]Cse 121 presentation on matrix [autosaved]
Cse 121 presentation on matrix [autosaved]
 
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf1. import java.util.Scanner; public class Alphabetical_Order {.pdf
1. import java.util.Scanner; public class Alphabetical_Order {.pdf
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
Two methods.pdf
Two methods.pdfTwo methods.pdf
Two methods.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 

More from angeldresses

oxidizing agent F2 I2 Fe2+ Li+ reducing ag.pdf
                     oxidizing agent F2  I2  Fe2+  Li+ reducing ag.pdf                     oxidizing agent F2  I2  Fe2+  Li+ reducing ag.pdf
oxidizing agent F2 I2 Fe2+ Li+ reducing ag.pdfangeldresses
 
Lewis Base is a substance that can gain electron .pdf
                     Lewis Base is a substance that can gain electron .pdf                     Lewis Base is a substance that can gain electron .pdf
Lewis Base is a substance that can gain electron .pdfangeldresses
 
let 3x mole of Fe react then moles of H2O is 4x m.pdf
                     let 3x mole of Fe react then moles of H2O is 4x m.pdf                     let 3x mole of Fe react then moles of H2O is 4x m.pdf
let 3x mole of Fe react then moles of H2O is 4x m.pdfangeldresses
 
X is a vector space but has no basis.SolutionX is a vector spa.pdf
X is a vector space but has no basis.SolutionX is a vector spa.pdfX is a vector space but has no basis.SolutionX is a vector spa.pdf
X is a vector space but has no basis.SolutionX is a vector spa.pdfangeldresses
 
Usually NGS (Next generation sequencing) is extensively used in unde.pdf
Usually NGS (Next generation sequencing) is extensively used in unde.pdfUsually NGS (Next generation sequencing) is extensively used in unde.pdf
Usually NGS (Next generation sequencing) is extensively used in unde.pdfangeldresses
 
There are 15 members of the show choir. In how many ways can you arr.pdf
There are 15 members of the show choir. In how many ways can you arr.pdfThere are 15 members of the show choir. In how many ways can you arr.pdf
There are 15 members of the show choir. In how many ways can you arr.pdfangeldresses
 
The Hubble Space Telescope (HST) is a space telescope that was carri.pdf
The Hubble Space Telescope (HST) is a space telescope that was carri.pdfThe Hubble Space Telescope (HST) is a space telescope that was carri.pdf
The Hubble Space Telescope (HST) is a space telescope that was carri.pdfangeldresses
 
IBrClF Solution IBr.pdf
                     IBrClF  Solution                     IBr.pdf                     IBrClF  Solution                     IBr.pdf
IBrClF Solution IBr.pdfangeldresses
 
hexacyanoferrate(III) because the given radical i.pdf
                     hexacyanoferrate(III) because the given radical i.pdf                     hexacyanoferrate(III) because the given radical i.pdf
hexacyanoferrate(III) because the given radical i.pdfangeldresses
 
The answer is e) they would get stuck in the membrane of the endopla.pdf
The answer is e) they would get stuck in the membrane of the endopla.pdfThe answer is e) they would get stuck in the membrane of the endopla.pdf
The answer is e) they would get stuck in the membrane of the endopla.pdfangeldresses
 
Step 1SolutionStep 1.pdf
Step 1SolutionStep 1.pdfStep 1SolutionStep 1.pdf
Step 1SolutionStep 1.pdfangeldresses
 
sorry bro...but where is section 5.2u might have missed postng th.pdf
sorry bro...but where is section 5.2u might have missed postng th.pdfsorry bro...but where is section 5.2u might have missed postng th.pdf
sorry bro...but where is section 5.2u might have missed postng th.pdfangeldresses
 
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdf
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdfPseudocode ExamplesChanged 15 December 1999A calculation is a st.pdf
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdfangeldresses
 
Process of transmission between A node and B nodeThere are differ.pdf
Process of transmission between A node and B nodeThere are differ.pdfProcess of transmission between A node and B nodeThere are differ.pdf
Process of transmission between A node and B nodeThere are differ.pdfangeldresses
 
Halogenated waste note All halogen containing o.pdf
                     Halogenated waste  note All halogen containing o.pdf                     Halogenated waste  note All halogen containing o.pdf
Halogenated waste note All halogen containing o.pdfangeldresses
 
PbI2 is only very slightly soluble in water, so the following equili.pdf
PbI2 is only very slightly soluble in water, so the following equili.pdfPbI2 is only very slightly soluble in water, so the following equili.pdf
PbI2 is only very slightly soluble in water, so the following equili.pdfangeldresses
 
option D is correctA thermodynamic cycle starts with a system in a.pdf
option D is correctA thermodynamic cycle starts with a system in a.pdfoption D is correctA thermodynamic cycle starts with a system in a.pdf
option D is correctA thermodynamic cycle starts with a system in a.pdfangeldresses
 
Fluorescence return from excited singlet state to.pdf
                     Fluorescence return from excited singlet state to.pdf                     Fluorescence return from excited singlet state to.pdf
Fluorescence return from excited singlet state to.pdfangeldresses
 
EDTA has 4 carboxylic acid groups, so adding a lo.pdf
                     EDTA has 4 carboxylic acid groups, so adding a lo.pdf                     EDTA has 4 carboxylic acid groups, so adding a lo.pdf
EDTA has 4 carboxylic acid groups, so adding a lo.pdfangeldresses
 
Ion channels are the membrane proteins which have pores. They allow .pdf
Ion channels are the membrane proteins which have pores. They allow .pdfIon channels are the membrane proteins which have pores. They allow .pdf
Ion channels are the membrane proteins which have pores. They allow .pdfangeldresses
 

More from angeldresses (20)

oxidizing agent F2 I2 Fe2+ Li+ reducing ag.pdf
                     oxidizing agent F2  I2  Fe2+  Li+ reducing ag.pdf                     oxidizing agent F2  I2  Fe2+  Li+ reducing ag.pdf
oxidizing agent F2 I2 Fe2+ Li+ reducing ag.pdf
 
Lewis Base is a substance that can gain electron .pdf
                     Lewis Base is a substance that can gain electron .pdf                     Lewis Base is a substance that can gain electron .pdf
Lewis Base is a substance that can gain electron .pdf
 
let 3x mole of Fe react then moles of H2O is 4x m.pdf
                     let 3x mole of Fe react then moles of H2O is 4x m.pdf                     let 3x mole of Fe react then moles of H2O is 4x m.pdf
let 3x mole of Fe react then moles of H2O is 4x m.pdf
 
X is a vector space but has no basis.SolutionX is a vector spa.pdf
X is a vector space but has no basis.SolutionX is a vector spa.pdfX is a vector space but has no basis.SolutionX is a vector spa.pdf
X is a vector space but has no basis.SolutionX is a vector spa.pdf
 
Usually NGS (Next generation sequencing) is extensively used in unde.pdf
Usually NGS (Next generation sequencing) is extensively used in unde.pdfUsually NGS (Next generation sequencing) is extensively used in unde.pdf
Usually NGS (Next generation sequencing) is extensively used in unde.pdf
 
There are 15 members of the show choir. In how many ways can you arr.pdf
There are 15 members of the show choir. In how many ways can you arr.pdfThere are 15 members of the show choir. In how many ways can you arr.pdf
There are 15 members of the show choir. In how many ways can you arr.pdf
 
The Hubble Space Telescope (HST) is a space telescope that was carri.pdf
The Hubble Space Telescope (HST) is a space telescope that was carri.pdfThe Hubble Space Telescope (HST) is a space telescope that was carri.pdf
The Hubble Space Telescope (HST) is a space telescope that was carri.pdf
 
IBrClF Solution IBr.pdf
                     IBrClF  Solution                     IBr.pdf                     IBrClF  Solution                     IBr.pdf
IBrClF Solution IBr.pdf
 
hexacyanoferrate(III) because the given radical i.pdf
                     hexacyanoferrate(III) because the given radical i.pdf                     hexacyanoferrate(III) because the given radical i.pdf
hexacyanoferrate(III) because the given radical i.pdf
 
The answer is e) they would get stuck in the membrane of the endopla.pdf
The answer is e) they would get stuck in the membrane of the endopla.pdfThe answer is e) they would get stuck in the membrane of the endopla.pdf
The answer is e) they would get stuck in the membrane of the endopla.pdf
 
Step 1SolutionStep 1.pdf
Step 1SolutionStep 1.pdfStep 1SolutionStep 1.pdf
Step 1SolutionStep 1.pdf
 
sorry bro...but where is section 5.2u might have missed postng th.pdf
sorry bro...but where is section 5.2u might have missed postng th.pdfsorry bro...but where is section 5.2u might have missed postng th.pdf
sorry bro...but where is section 5.2u might have missed postng th.pdf
 
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdf
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdfPseudocode ExamplesChanged 15 December 1999A calculation is a st.pdf
Pseudocode ExamplesChanged 15 December 1999A calculation is a st.pdf
 
Process of transmission between A node and B nodeThere are differ.pdf
Process of transmission between A node and B nodeThere are differ.pdfProcess of transmission between A node and B nodeThere are differ.pdf
Process of transmission between A node and B nodeThere are differ.pdf
 
Halogenated waste note All halogen containing o.pdf
                     Halogenated waste  note All halogen containing o.pdf                     Halogenated waste  note All halogen containing o.pdf
Halogenated waste note All halogen containing o.pdf
 
PbI2 is only very slightly soluble in water, so the following equili.pdf
PbI2 is only very slightly soluble in water, so the following equili.pdfPbI2 is only very slightly soluble in water, so the following equili.pdf
PbI2 is only very slightly soluble in water, so the following equili.pdf
 
option D is correctA thermodynamic cycle starts with a system in a.pdf
option D is correctA thermodynamic cycle starts with a system in a.pdfoption D is correctA thermodynamic cycle starts with a system in a.pdf
option D is correctA thermodynamic cycle starts with a system in a.pdf
 
Fluorescence return from excited singlet state to.pdf
                     Fluorescence return from excited singlet state to.pdf                     Fluorescence return from excited singlet state to.pdf
Fluorescence return from excited singlet state to.pdf
 
EDTA has 4 carboxylic acid groups, so adding a lo.pdf
                     EDTA has 4 carboxylic acid groups, so adding a lo.pdf                     EDTA has 4 carboxylic acid groups, so adding a lo.pdf
EDTA has 4 carboxylic acid groups, so adding a lo.pdf
 
Ion channels are the membrane proteins which have pores. They allow .pdf
Ion channels are the membrane proteins which have pores. They allow .pdfIon channels are the membrane proteins which have pores. They allow .pdf
Ion channels are the membrane proteins which have pores. They allow .pdf
 

Recently uploaded

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersChitralekhaTherkar
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Recently uploaded (20)

APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Micromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of PowdersMicromeritics - Fundamental and Derived Properties of Powders
Micromeritics - Fundamental and Derived Properties of Powders
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

import java.util.Scanner; class AddTwoMatrix { public static vo.pdf

  • 1. import java.util.Scanner; class AddTwoMatrix { public static void main(String args[]) { int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println("Enter 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("Enter 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("Enter 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]; //replace '+' with '-' to subtract matrices System.out.println("Sum of entered matrices:-"); for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < n ; d++ ) System.out.print(sum[c][d]+"t"); System.out.println(); } } } Solution import java.util.Scanner; class AddTwoMatrix { public static void main(String args[]) { int m, n, c, d; Scanner in = new Scanner(System.in); System.out.println("Enter 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("Enter 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("Enter 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]; //replace '+' with '-' to subtract matrices System.out.println("Sum of entered matrices:-"); for ( c = 0 ; c < m ; c++ ) { for ( d = 0 ; d < n ; d++ ) System.out.print(sum[c][d]+"t"); System.out.println(); } } }