title: finding out if all the digits of a number are equal
body: <p>So I want to start by saying that I already solved the problem, but there is something that is bugging me,</p>
  <p>Here is the code first:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  int flag = 1;
  
  int controlNumber(int);
  
  int main() {    
      int array[10] = { 233, 45, 777, 81, 999999, 36, 90, 88, 11, 61 };   
      int i;  
      int c;  
  
      for (i = 0; i &lt; 10; i++) {
          printf(&quot;%d &gt;&gt;  &quot;, array[i]);
          c = controlNumber(array[i]);
          if (c == 1) {           
              printf(&quot;all digits are equal\n&quot;);
          } else {
              printf(&quot;not all digits are equal\n&quot;);
          }
      }
      return 0;
  }
  
  int controlNumber(int a) {
      int q = a;
      int r = a % 10;
      int temp;
      
      while (q != 0) {
          temp = q % 10;
          if (temp == r) {
              q = q / 10;
          } else {
              flag = 0;
              return flag;
          }
      }
      return flag;
  }
  </code></pre>
  <p>The code works only if the global variable <code>flag</code> is made local inside the scope of the function <code>controlNumber</code> with a value of <code>1</code>, and I can't really figure out why that is the case since the logic should still be the same.</p>
  <p>Also, I'm still a beginner to some extend so I apologize for any indentation errors.</p>