C++ Power Operator
The power function looks like
pow()
inside we put argument ten and raise it to the second powerpow(10,2)
return100.
pow() Syntax
The syntax of the pow() function is:
pow(double base, double exponent);
pow() Parameters
The pow() function takes two parameters:
- base – the base value
- exponent – exponent of the base
C++ Power
Use Power Operator in c++
pow() function is not made available to us. By default, we need to import <cmath>
#include <iostream> #include <cmath> using std::cout; using std::cin; int main() { int base, exponent; cout << "Enter Base : "; cin >> base; cout << "Enter Exponent : "; cin >> exponent; cout << pow(base, exponent); }
output :
Enter Base : 2 Enter Exponent : 4 16
We get a huge number if we have
pow(10,10)
return1e+10
1 times10
to the 10th power.We can assign a variable to that.
#include <iostream> #include <cmath> using namespace std; int main() { int base, exponent; double result; base = 6; exponent = 2; result = pow(base, exponent); cout << result << endl; return 0; }
output 36