We can easily find out the power of a number by using pow() function of <math.h> library.
It takes two arguments base and exponent and gives the result.
Example:
- Input the base: 23
Input the exponent: 4
Answer: 279841
- Input the base: 9
Input the exponent: -3
Answer: 0.00137174
# Algorithm
- Take base and exponent as input from user.
- Result = pow(base,exponent).
- Print the result
Code:
// Program to find power of any number
#include <iostream>
#include<math.h>
using namespace std;
int main(){
float base, expo;
cout << "Input the base: ";
cin >> base;
cout << "Input the exponent: ";
cin >> expo;
cout << "Answer: " << pow(base, expo);
}
Report Error/ Suggestion