In this program, base and exponent are assigned values 3 and 4 respectively.
Using the while loop, we keep on multiplying result by base until exponent becomes zero.
In this case, we multiply result by base 4 times in total, so result = 1 * 3 * 3 * 3 * 3 = 81.
C++ Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | #include <iostream> using namespace std; int main() { system ("CLS"); //to clear the screen int base,exponent,res; cout<<"Enter value of base: "; cin>>base; cout<<"Enter value of exponent: "; cin>>exponent; long result = 1; while (exponent != 0) { result *= base; --exponent; } cout<<"Result="<<result; return 0; } |