...

/

Solution Review: Calculate the Power of a Number

Solution Review: Calculate the Power of a Number

Let's see the detailed solution review of the challenge given in the previous lesson.

We'll cover the following...

Solution #

Press + to interact
#include <iostream>
using namespace std;
int main() {
// Initialize variable
int base = 2, exponent = 3, result = 1;
// for loop initialization
for (int counter = 1; counter <= exponent; counter++) {
// for loop body
result *= base;
}
// Exit for loop
cout << result;
return 0;
}

Explanation

...