0% found this document useful (0 votes)
3 views3 pages

Lab Program 1

Uploaded by

orangemewtw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Lab Program 1

Uploaded by

orangemewtw
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LabProgram1: Develop a java program to add two

matrices of suitable order N (the value of n should


be read from command line arguments)
Source code:
package anujna;

import java.util.Scanner;

public class AddMatrixPgm

public static void main(String[] args)

int row, col,i,j;

Scanner in = new Scanner(System.in);

System.out.println("Enter the number of rows");

row = in.nextInt();

System.out.println("Enter the number columns");

col = in.nextInt();

int mat1[][] = new int[row][col];

int mat2[][] = new int[row][col];

int res[][] = new int[row][col];

System.out.println("Enter the elements of matrix1");

for(i= 0;i<row;i++ )
{

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

mat1[i][j] = in.nextInt();

System.out.println();

System.out.println("Enter the elements of matrix2");

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

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

mat2[i][j] = in.nextInt();

System.out.println();

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

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

res[i][j] = mat1[i][j] + mat2[i][j] ;

System.out.println("Sum of matrices:-");

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

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

System.out.print(res[i][j]+"\t");

System.out.println();
}

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy