Type Here to Get Search Results !

Write a Java Program to determine the Addition of two matrices.

 import java.io.*; 

import java.util.*; 

class MatrixAdd 

public static void main(String arg[]) 

int i=0,j=0,k=0; 

Scanner s=new Scanner(System.in); 

System.out.println("Enter order of matrix for A&B"); 

int m=s.nextInt(); 

int n=s.nextInt(); 

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

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

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

System.out.println("Enter elements for matrix A"); for(i=0;i<m;i++) 

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

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

  

System.out.println("Enter elements for matrix B ");  for(i=0;i<m;i++) 

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

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

  

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

 { 

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

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

 } 

 } 

System.out.println("Addition of resultant matrix is:");  for(i=0;i<m;i++) 

 { 

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

 { 

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

 } 

 System.out.println("\n"); 

 } 

}

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

Featured post

M

M