Question
program to Largest element in boundary elements of matrix
Matrix = [9, 8, 7]
[6, 5, 4]
[3, 2, 1]
LARGEST ELEMENT IN BOUNDARY ELEMENT OF MATRIX:9
Share code with your friends
Share on whatsapp
Share on facebook
Share on twitter
Share on telegram
Code
Java
Python
Java
import java.util.Scanner;
public class largestBoundaryElementsOfMatrix
{
public static void main(String[] args)
{
int row=0,col=0,i=0,j=0,max=0;
int a[][];
Scanner sc=new Scanner(System.in);
System.out.println("ENTER THE NUMBER OF ROW OF MATRIX");
row=sc.nextInt();
System.out.println("ENTER THE NUMBER OF COLUMN OF MATRIX");
col=sc.nextInt();
a=new int[row][col];
System.out.println("ENTER THE ELEMENTS IN MATRIX");
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
a[i][j]=sc.nextInt();
}
}
System.out.println("MATRIX:");
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
System.out.print(a[i][j]+" ");
}
System.out.println();
}
max=a[0][0];
for(i=0;i< row;i++)
{
for(j=0;j< col;j++)
{
if(i==0 ||j==0||i==(row-1)||j==(col-1))
{
if(a[i][j]> max)
{
max=a[i][j];
}
}
}
}
System.out.println("LARGEST BOUNDARY ELEMENT IN MATRIX:"+max);
}
}
Python
import numpy as np
row=int(input("Enter number of rows:"))
columns=int(input("Enter number of columns:"))
matrix=np.empty([row,columns],dtype=np.int)
# Taking input from user
print("Enter elements in matrix:")
for i in range(0,row):
for j in range(0,columns):
print("(",(i+1),",",(j+1),")",":",end="")
matrix[i,j]=int(input())
#printing the matrix
print("Matrix:")
for i in range(0, row):
print(matrix[i])
largestBoundaryElement=matrix[0,0]
#Finding Largest boundary elements
for i in range(0,row):
for j in range(0,columns):
if(i==0 or j==0 or i==(row-1) or j==(columns-1)):
if(matrix[i,j]>largestBoundaryElement):
largestBoundaryElement=matrix[i,j]
print("Largest boundary elements:",largestBoundaryElement)
Coding Store
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale
ICSE QUESTION PAPER WITH SOLUTION(PROGRAMMING ONLY)
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale
ICSE QUESTION PAPER WITH SOLUTION(PROGRAMMING ONLY)
Sale
ISC QUESTION PAPERS WITH SOLUTION(PROGRAMMING ONLY)
Sale