title: Calculating sum of digits of 2^n in C
body: <p>I am new to C and trying to write a program that calculates the sum of the digits of 2^n, where <strong>n&lt;10^8.</strong></p>
  
  <p>For example, for 2^10, we'd have 1+0+2+4, which is 7.</p>
  
  <p>Here's what I came up with:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;math.h&gt;
  
  int main()
  {
     int n, t, sum = 0, remainder;
  
     printf("Enter an integer\n");
     scanf("%d", &amp;n);
  
     t = pow(2, n);
  
     while (t != 0)
     {
        remainder = t % 10;
        sum       = sum + remainder;
        t         = t / 10;
     }
  
     printf("Sum of digits of 2 to the power of %d = %d\n", n, sum);
  
     return 0;
  }
  </code></pre>
  
  <p>The problem is: the program works fine with numbers smaller than 30. Once I set n to a number higher than 30, the result is always <strong>-47</strong>.</p>
  
  <p>I really do not understand this error and what causes it.</p>