Answer to Question #155322 in C++ for zain ul abdeen

Question #155322

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.


1
Expert's answer
2021-01-16T11:49:01-0500

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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog