Program to find minimum and maximum element of a matrix.

import java.io.*;
class test
{
public static void main(String[] asd)throws IOException
{
BufferedReader obj=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter the values of Rows and Columns of Matrix.");
String num=obj.readLine();
int r=Integer.parseInt(num);
num=obj.readLine();
int c=Integer.parseInt(num);
int m[][]= new int[r][c][/c];
int  max, min;
System.out.println("Enter the values of the matrix not more then "+(r*c)+".");
for(int i=0;i<r;i++)
for(int j=0;j<c;j++)
{
num=obj.readLine();
m[i][j]=Integer.parseInt(num);
}
System.out.println("Original matrix::");
for(int i=0;i<r;i++)
{    for(int j=0;j<c;j++)
{
System.out.print(m[i][j]+"    ");
}
System.out.println();
}
// MAXIMUM element of the matrix
max=m[0][0];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(m[i][j]>max)
max=m[i][j];
}
}
System.out.println("Maximum of the matrix is "+max+".");
//MINIMUM element of the matrix
min=m[0][0];
for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
if(m[i][j]<min)
min=m[i][j];
}
}
System.out.println("Minimum of the matrix is "+min+".");

}




}
Advertisements

One thought on “Program to find minimum and maximum element of a matrix.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s