how do you do powers with a for loop?
how do you do powers with a for loop?
Just loop n times and multiply val by itself:
-PreludeCode:int power ( int val, int n ) { int ret = 1; for ( int i = 0; i < n; i++ ) ret *= val; return ret; }
My best code is written with the delete key.
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.