title: Implement a sum formula in C
body: <p>So, i need to implement this formula in C:</p>
  
  <p><a href="https://i.stack.imgur.com/qFpl7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qFpl7.png" alt="enter image description here"></a></p>
  
  <p>Where n is entered by the user and must be >= 1. <em>Ci</em> is the i-th digit of the number <em>n</em> with <em>k</em> digits, and <em>Ci</em> with the line is the complement of <em>Ci</em> (digit + complement = 9).
  For example, the number 21262 fulfills this equation because:</p>
  
  <p><strong>21262</strong> = 7^5 + 8^4 + 7^3 + 3^2 + 7^1 = 16807 + 4096 + 343 + 9 + 7 = <strong>21262</strong></p>
  
  <p>I've tried making an algorithm and turning it into a C program, but when I execute, something goes wrong. I'm having trouble formulating the loop that does the k-i+1 power.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  int main() {
  int n, t, k, c, i, s, power, j;
  do {
      printf("Enter n = ");
      scanf("%d", &amp;n);
  } while (n &lt; 1);
  
  t = n;                    // Here we save the value of n, and operate with t
  k = 0;                          // k counts the number of digits 
  while (t &gt; 0) {
      t = t / 10;      
      k++;                        // k = number of digits
  }                                
  t = n;
  s = 0;
  
  for (i = 1; i &lt;= k; i++) {            // Starts the sum from i to k
      c = 9 - t % 10;                   // Complements the digits
      power = 1;
  
      for (j = 1; j &lt;= k-i+1; j++)      // Start of loop that powers th number
          power = c * power;
      s = s + power;
      t = t / 10;
  }
  
  if (s == n)
      printf("The number fulfills the equation");
  else
      printf("The number doesn't fulfill the equation");
  return 0;
  }
  </code></pre>
  
  <p>As you can see, I tried solving the power problem by making a loop that multiplies c complement by itself k-i+1 times. But something's not right. Please help!</p>