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

Question #155320

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 for loops.


1
Expert's answer
2021-01-17T08:09:11-0500
#include <iostream>

using namespace std;

int main()

{

   int num1,num2, answer=1;/*variables are declared and answer is initialized with a value of 1*/

   cout << "Enter first number==> " << endl;

   cin >> num1;/*user input is requested and stored as num1*/

   cout << "Enter second number==> " << endl;

   cin >> num2;/*user input is requested and stored as num2*/

   for(int i=1;i<=num2;i++)/*loop runs from 1 to num2, the user declared power*/

   {

       answer=answer*num1;/*value of answer is calculated by multiplying num1 by itself until loop ends*/

   }

   cout << num1<<" raised to "<<num2<<" is==> "<<answer;/*prints out answer*/

   return 0;

}

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