compute power of number

To compute the power of a number in C++, you can use the pow() function from the <cmath> library. This function takes two arguments: the base and the exponent. The pow() function returns the result of raising the base to the power of the exponent.

Here is an example code snippet that demonstrates how to compute the power of a number in C++:

#include <iostream>
#include <cmath>

int main() {
    double base, exponent, result;

    // Prompt the user to enter the base and exponent
    std::cout << "Enter the base: ";
    std::cin >> base;

    std::cout << "Enter the exponent: ";
    std::cin >> exponent;

    // Compute the power using the pow() function
    result = pow(base, exponent);

    // Display the result
    std::cout << "Result: " << result << std::endl;

    return 0;
}

In this code, we first declare three variables: base, exponent, and result. These variables will hold the values entered by the user and the result of the computation.

We then use std::cout to prompt the user to enter the base and exponent. The values entered by the user are stored in the base and exponent variables using std::cin.

Next, we use the pow() function to compute the result. The pow() function takes the base and exponent variables as arguments and returns the result, which is stored in the result variable.

Finally, we use std::cout to display the result to the user.

That's how you can compute the power of a number in C++ using the pow() function.