Find Highest and Lowest Element of a Matrix
Here you will get and learn the example code of C++ program to find highest and lowest element of a matrix.
Example of C++ Program to Find Highest and Lowest Element of a Matrix
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | //C++ Program to Find Highest and Lowest Element of a Matrix #include<iostream> using namespace std; main() { int x[5][5],i,j,min,max; int r,c; //input size of matrix cout<<"\nInput No of Rows & Columns (max : 5,5) :"; cin>>r>>c; //input elements in matrix cout<<"\nInput the Elements of Matrix : "; for(i=0;i<r;i++) { for(j=0;j<c;j++) cin>>x[i][j]; } //search element min, and max min=x[0][0]; max=x[0][0]; for(i=0;i<r;i++) { for(j=0;j<c;j++) { if(x[i][j]<min) { min=x[i][j]; } if(x[i][j]>max) { max=x[i][j]; } } } cout<<"\nHighest Number is :"<<max; cout<<"\nLowest Number is :"<<min; return 0; } |
Output
Input No of Rows & Columns (max : 5,5) :3
3
Input the Elements of Matrix : 5
3
4
12
43
87
65
34
9
Highest Number is :87
Lowest Number is :3
Other Similar Programs
Check out our other C++ programming Examples