ismaeil

Matrix

Jun 10th, 2020
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. using namespace std;
  4.  
  5. bool is_peak(int Mat[5][5] ,int Rows ,int Cols ,int i ,int j){
  6.  
  7.     bool flag = true;
  8.     for(int k=0 ; k<Cols ; k++){
  9.         if( Mat[i][k] > Mat[i][j] )
  10.             flag = false;
  11.     }
  12.     return flag;
  13. }
  14.  
  15. int main()
  16. {
  17.     int Cols = 5 ,Rows = 5 ,Mat[5][5];
  18.  
  19.     cout << "Enter The Matrix : " << endl;
  20.     for(int i=0 ; i<Rows ; i++){
  21.         cout << "Enter The Elements OF the " << i + 1 << "th Row" << endl;
  22.         for(int j=0 ; j<Cols ; j++){
  23.             cin >> Mat[i][j];
  24.         }
  25.     }
  26.  
  27.     cout << endl << "---------------------------" << endl;
  28.     cout << "Our Matrix : " << endl;
  29.     for(int i=0 ; i<Rows ; i++){
  30.         for(int j=0 ; j<Cols ; j++)
  31.             cout << setw(4) << Mat[i][j];
  32.         cout << endl;
  33.     }
  34.  
  35.     int NumOFTests;
  36.     cout << "Enter The Number OF Tests You Want :";
  37.     cin >> NumOFTests;
  38.  
  39.     for(int Test = 0 ; Test < NumOFTests ; Test++){
  40.             int i ,j;
  41.             cout << "Chose The Row and The Col Of Your Element : ";
  42.             cin >> i >> j;
  43.  
  44.             if( is_peak(Mat ,Rows ,Cols ,i ,j) == true )
  45.                 cout << "is true ( Is Largest )" << endl;
  46.             else
  47.                 cout << "is false ( Is Not Largest )" << endl;
  48.     }
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment