Write a program which takes two integers (num1 and num2) as input from the user. The program should display the result of num1 to the power num2. i) The program can use only while loops.
So, solution with while loops is the following:
#include <iostream>
using namespace std;
int main()
{
int num1 = 0, num2 = 0, result=1;
cout << "Enter num1: ";
cin >> num1;
cout << "Enter num2: ";
cin >> num2;
while (num2) {
result *= num1;
num2--;
}
cout << "The result is: " << result;
}
Comments
Leave a comment