title: C++ Handling big numbers
body: <p>Okay, I have to do simple task for my c++ class. Two functions, first is Fibonacci sequence, second some random sequence (finding <code>e</code>). It looks like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;cstdlib&gt;
  #include &lt;string&gt;
  #include &lt;math.h&gt;
  
  void fib(int number)
  {
      int a=0, b=1;
      printf("%d\n", a); 
      for (; number&gt;0; number--)
      {
          printf("%d\n", b);
          b+=a;
          a = b-a;
      }
  }
  
  void e_math(unsigned int number)
  {
      for (double n = 1; number&gt;0; number--, n++)
      {
          printf("%f\n", pow((1+1/n), n));
      }
  }
  
  int main(int argc, char** argv)
  {
      if (std::string(argv[2])=="f") fib(atoi(argv[1])-1);
      if (std::string(argv[2])=="c") e_math(atoi(argv[1])-1);
      else printf("Bad argument\n");
  }
  </code></pre>
  
  <p>So at the end I did <code>g++ main.cpp -o app;./app 10 f</code>. It worked perfectly. But when I thought: Hmm, maybe lets check for bigger number, and added 50 it just messed up. I mean it did good for about 40 sequence numbers (checked with Python), but then it started to <code>printf()</code> negatives etc. I figured it's probably about <code>int</code> range. So I changed <code>int a=0, b=1</code> to <code>long long a=0, b=1</code>, but still it prints the same (I still use <code>printf("%d..)</code>, because <code>%lld</code> does not work</p>