title: Write a function that for a given a non-negative int n, returns the count of the occurrences of 9 as a digit
body: <p>I can't solve this problem and I've been trying to wrap my head around it for a couple of days now. Here's the full text of the problem:</p>
  <blockquote>
  <p>Write a function that for a given a non-negative int <code>n</code>, returns the count of the occurrences of <code>9</code> as a digit, except that a <code>9</code> with another <code>9</code> immediately to its left counts double, so <code>9912349</code> yields 4.</p>
  </blockquote>
  <p>The problem has two parts, a) and b).</p>
  <p>a) part requires that this problem be solved using recursion, and</p>
  <p>b) part requires iteration.</p>
  <p>I'm mostly having trouble with the recursive problem. Here's my code for a) part:</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  /* Write a function that for a given a non-negative int n, computes the count of the 
  occurrences of 9 as a digit, except
  that an 9 with another 9 immediately to its left counts double, so 9914329 yields 4. */
  
  int recursiveNines(int mynumber) {
      int counter = 0;
      if (mynumber = 0) {
          return 0;
      }
      if (mynumber / 10 == 9) {
          counter++;
      }
      else if (mynumber / 10 == 9 &amp;&amp; mynumber / 100 == 9) {
          counter += 2;
      }
      return mynumber + recursiveNines(mynumber / 10);
  }
  </code></pre>
  <p>I think the function is okay, but I'm unsure how to return the final counter and therefore test my function.</p>
  <p>Here's my code for the iteration of this problem:</p>
  <pre><code>int iterateNines(int mynumber) {
      int counter = 0;
      do {
          if (mynumber / 10 == 9) {
              counter++;
          }
          else if (mynumber / 10 == 9 &amp;&amp; mynumber / 100 == 9) {
              counter+=2;
          }
      } while (mynumber != 0);
  
      return counter;
  }
  </code></pre>