📅  最后修改于: 2023-12-03 15:29:50.414000             🧑  作者: Mango
The math.pow()
function is a part of C++ STL math library. It is used to calculate the power of a given number. This function requires two arguments - the base and the exponent. The function returns the result of the base raised to the power of the exponent.
double pow(double base, double exponent);
The function returns the result of the base raised to the power of the exponent.
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double base, exponent, result;
cout << "Enter base: ";
cin >> base;
cout << "Enter exponent: ";
cin >> exponent;
result = pow(base, exponent);
cout << base << " raised to the power of " << exponent << " is " << result << endl;
return 0;
}
In this example, the user is prompted to enter the base and the exponent, and the pow()
function is used to calculate the result. The result is then printed to the console.
Enter base: 2
Enter exponent: 3
2 raised to the power of 3 is 8
The math.pow()
function is a useful function in the C++ STL math library. It allows us to easily calculate the power of a given number with minimal code. However, it is important to note that this function may not be efficient for very large numbers or large exponents.