Program to find the Highest and Lowest values of a matrix in CPP (C plus plus)
Program to find the Highest and Lowest values of a matrix in CPP (C plus plus)
In this tutorial, we will learn about the Program to find the Highest and Lowest values of a matrix in CPP (C plus plus).
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 |
#include<iostream> using namespace std; int main() { int r; int c; int array[10][10]; int i; int j; int highest; int lowest; cout<<"Please enter number of rows and columns: "; cin>>r>>c; cout<<endl<<"Please enter matrix: "<<endl; for(i=0;i<r;++i) { for(j=0;j<c;++j) cin>>array[i][j]; } highest=array[0]
[0]; lowest=array[0][0]; for(i=0;i<r;++i) { for(j=0;j<c;++j) { if(array[i][j]>highest) highest=array[i][j]; else if(array[i][j]<lowest) lowest=array[i][j]; } } cout<<endl<<"Highest element is:"<<highest<<endl<<"Lowest element is:"<<lowest<<endl; return 0; } |
Output: