pow in c++
#include <iostream>
#include <cmath>
int main() {
double base = 2.0;
double exponent = 3.0;
double result = pow(base, exponent);
std::cout << "Result: " << result << std::endl;
return 0;
}
This C++ program includes the necessary headers for input/output operations (iostream
) and mathematical functions (cmath
). It defines a main
function.
Inside the main
function:
1. double base = 2.0;
: Declares and initializes a variable base
with the value 2.0.
2. double exponent = 3.0;
: Declares and initializes a variable exponent
with the value 3.0.
3. double result = pow(base, exponent);
: Computes the result of raising the base
to the power of exponent
using the pow
function from the cmath
library and assigns it to the variable result
.
4. std::cout << "Result: " << result << std::endl;
: Outputs the result to the standard output stream.
Finally, return 0;
indicates successful program execution.