title: Finding all saddle points in a matrix c++
body: <p>I'm working on a code that finds all saddle points in a matrix. Both smallest in their row and biggest in their column, and biggest in their row and smallest in their column fall under the definition (of my university) of a saddle point. Being a beginner I managed to get half of it done (finding saddle points which are smallest in their row and biggest in their column) by copying parts of what we've done in class and typing it myself. I have been stuck on it for quite some time and can't figure how to add the saddle points which are biggest in their row and smallest in their column to the program. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cstdlib&gt;
  using namespace std;
  
  int a[10][10];
  int x, y;
  
  int pos_max(int j) //saddle points check
  {
      int max = 0;
      for (int i = 1; i &lt;= x - 1; i++) {
          if (a[i][j] &gt; a[max][j]) {
              max = i;
          }
      }
      return max;
  }
  
  int main() {
      cout &lt;&lt; "Enter the number of rows: ";
      cin &gt;&gt; x;
      cout &lt;&lt; "Enter the number of columns: ";
      cin &gt;&gt; y;
      cout &lt;&lt; "----------------------------" &lt;&lt; endl;
  
      for (int i = 0; i &lt;= x - 1; i++) //input of the matrix
          for (int j = 0; j &lt;= y - 1; j++) {
              cout &lt;&lt; "a[" &lt;&lt; i + 1 &lt;&lt; ", " &lt;&lt; j + 1 &lt;&lt; "] = ";
              cin &gt;&gt; a[i][j];
          }
      cout &lt;&lt; "----------------------------\n";
      for (int i = 0; i &lt;= x - 1; i++) //visualization of the matrix
      {
          for (int j = 0; j &lt;= y - 1; j++)
              cout &lt;&lt; a[i][j] &lt;&lt; " ";
          cout &lt;&lt; endl;
      }
      cout &lt;&lt; "----------------------------\n";
  
      int r;
      int flag = 0;
      int i = y;
  
      for (int j = 0; j &lt;= y - 1; j++) {
          r = pos_max(j);
          for (i = 0; i &lt;= y - 1; i++) {
              if (a[r][i] &lt; a[r][j]) {
                  break;
              }
          }
          if (i == y) {
              cout &lt;&lt; "Saddle points are: ";
              cout &lt;&lt; "a[" &lt;&lt; r + 1 &lt;&lt; ", " &lt;&lt; j + 1 &lt;&lt; "] = " &lt;&lt; a[r][j] &lt;&lt; "\n";
              flag = 1;
          }
      }
      if (flag == 0) {
          cout &lt;&lt; "No saddle points\n";
      }
      cout &lt;&lt; "----------------------------\n";
      return 0;
  }
  </code></pre>