[Solved] Taking power with loop(with-out pow() function) [closed]


Here is a way you could achieve your purpose.

int num = 2; // for example
int out = 1;
for (int exp = 1; exp <= 10; exp++)
{
    out *= num;
    printf("%d\n", out);
}

Remarks about your code:

  • Your inner while loop is infinite if num and expnt are both different from 0.
  • Assigning preExpnt to the value of expnt at each step and multiplying by num would display a something like: 1*n 2*n 3*n 4*n ... if expnt starts at 1.

3

solved Taking power with loop(with-out pow() function) [closed]