title: Count number of digits - which method is most efficient?
body: <p>There are more than one solution for finding the-number-of-digits in a given number.</p>
  
  <p>For example:</p>
  
  <p>Method-1:</p>
  
  <pre><code>int findn(int num)
  {
      char snum[100];
      sprintf(snum, "%d", num);
      return strlen(snum);
  }
  </code></pre>
  
  <p>Method-2:</p>
  
  <pre><code>int findn(int num)
  {
      if (num == 0) return 1;
      int n = 0;
      while(num) {
          num /= 10;
          n++;
      }
      return n;
  }
  </code></pre>
  
  <p>Method-3:</p>
  
  <pre><code>int findn(int num)
  {
      /* math.h included */
      return (int) log10(num) + 1;
  }
  </code></pre>
  
  <p>The question is - what is the most efficient method? I know method-2 is <code>O(n)</code> but what about method-1 and method-3? How do I find the run-time complexity of library functions?</p>