title: check column and row in sodoku- C programming
body: <blockquote>
  <p>I'm trying to check if number (from 1 to n)</p>
  <p>appears more than once in</p>
  <p>row or column in sodoku board</p>
  </blockquote>
  <p>I wrote a code that goes over each row and column and checks the numbers between 1 to n (every time checking number at a time after finishing with row 0 (for example) goes to the next one (if it wasn't true in the row before)</p>
  <blockquote>
  <p>my code is working just if there is a number</p>
  <p>appearing more than once</p>
  <p>in row 0 (if there is in other rows it returns nothing!)</p>
  <p>and for the column it doesn't return any thing</p>
  </blockquote>
  <p>this is a matrix that I use for the test (matrix with solution and I change numbers in rows or columns):</p>
  <pre><code>7 1 0 0 0 0 6 0 9
  2 0 0 0 0 3 0 0 0
  0 0 0 1 5 0 0 0 8
  0 0 7 0 0 0 0 9 0
  0 0 6 0 0 0 7 0 0
  0 2 0 0 0 0 4 0 0
  1 0 0 0 2 9 0 0 0
  0 0 0 3 0 0 0 0 4
  9 0 5 0 0 0 0 8 6
  </code></pre>
  <p>and this is my code:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;stdbool.h&gt;
  
  
  #define MAX4USED 10
  
  
  int n; //size of the sodoku board
  
  bool CheckAppearingInRow(int matrix [n][n]) {
      int used[MAX4USED] = {0};
      int index = 1;
      int row = 0;
      while (index &lt;= n) {
          for(int j = 0; j &lt; n; j++) {
              if(matrix[row][j] == index ) {
                  used[index] +=1;
              }
          }
          for(int i = 0; i &lt;= n ; i++) {
              if (used[i] &gt; 1) {
                  return true;
              }
              used[i] = 0;
          }
          index += 1;
      }
      row += 1;
      while (row &lt; n) {
          CheckAppearingInRow(matrix);
      }
      return false;
  }
  
  
  
  bool CheckAppearingInColumn(int matrix [n][n]) {
      int used[MAX4USED] = {0};
      int index = 1;
      int col = 0;
      while (index &lt;= n) {
          for(int i = 0; i &lt; n; i++) {
              if(matrix[i][col] == index ) {
                  used[index] +=1;
              }
          }
          for(int i = 0; i &lt;= n ; i++) {
              if (used[i] &gt; 1) {
                  return true;
              }
              used[i] = 0;
          }
          index += 1;
      }
      col += 1;
      while(col &lt; n){
           CheckAppearingInColumn(matrix);
      }
      return false;
  }
  
  
  int main() {
      printf(&quot;Please enter your sodoku dimension:&quot;);
      scanf(&quot;%d&quot;, &amp;n);
      int a[n][n];
      printf(&quot;\nInsert your sodoku board\n&quot;);
      printf(&quot;Instruction: Enter 0 for blank\n&quot;);
      for(int i=0; i&lt;n; i++){
         for(int j=0; j&lt;n; j++) {
           scanf(&quot;%d&quot;, &amp;a[i][j]);
         }
      }
      if (CheckAppearingInRow(a)== true || CheckAppearingInColumn(a) == true) {
          printf(&quot;\nNo solution!\n&quot;);
      } 
      return 0;
  }
  </code></pre>