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
andexpnt
are both different from 0. - Assigning
preExpnt
to the value ofexpnt
at each step and multiplying bynum
would display a something like:1*n 2*n 3*n 4*n ...
ifexpnt
starts at 1.
3
solved Taking power with loop(with-out pow() function) [closed]