Q:

Write a program in C++ to find power of any number using for loop

0

Write a program in C++ to find power of any number using for loop

Sample Output:

 Find power of any number using for loop:                              
---------------------------------------------                          
 Input the base: 2                                                     
 Input the exponent: 5                                                 
2 ^ 5 = 32

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>
using namespace std;
int main()
{
    int bs, ex, num=1,i;
    cout << "\n\n Find power of any number using for loop:\n";
    cout << "---------------------------------------------\n";
    cout << " Input the base: ";
    cin >> bs;
    cout << " Input the exponent: ";
	cin>>ex;
	
    for (i = 1; i <=ex; i++) 
    {
       num=num*bs;
    }
	cout <<bs<<" ^ "<<ex<<" = "<<num<<endl ;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now