There are two ways to express nth power in C: 1. pow() function; 2. ^ operator. The pow() function is located in the
header file, and the ^ operator has higher precedence than * and /, but lower than and -.
Power operation in C
How to express nth power in C?
There are two ways to express nth power in C:
1. Use the pow() function
#include <cmath> double result = pow(base, exponent);
where:
base
is the base. exponent
is the exponent. result
is the result. 2. Use ^ operator
double result = base ^ exponent;
Example:
Calculate 2 5th power:
Use pow()
Function:
#include <cmath> double result = pow(2, 5);
Use ^ Operator:
double result = 2 ^ 5;
Note:
and
/, but lower than
and
-. Therefore, you need to be careful when using the
^ operator. The
The above is the detailed content of How to express nth power in c++. For more information, please follow other related articles on the PHP Chinese website!