...
- Solution
We'll learn different approaches to solve the previous challenge.
// power1.cpp#include <iostream>int power(int m, int n){ int r = 1; for(int k=1; k<=n; ++k) r*= m; return r;}int main(){ std::cout << power(2,10) << std::endl;}
We’re using a for loop to compute the power. The loop runs a total of n times by multiplying the number m by r for every iteration of the loop in line 7.
for
n
m
r
For a more in-depth insight into the solution above, click here ...