WAP to add two given matrices in Java

600 views
464 views

Published on

WAP to add two given matrices in Java

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
600
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
14
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

WAP to add two given matrices in Java

  1. 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. 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(); } }
  3. 3. OUTPUT:-

×