how do you do powers with a for loop?

Printable View

- 11-24-2002sonictpower
how do you do powers with a for loop?

- 11-24-2002Prelude
Just loop n times and multiply val by itself:

Code:`int power ( int val, int n )`

{

int ret = 1;

for ( int i = 0; i < n; i++ )

ret *= val;

return ret;

}

- 11-24-2002bc17
There is a function called exp();. This is found in math.h. The syntax is

exp(number,power);

I know this isn't a for loop, but it is a differrent method.