In C language, there are two ways to express 10 to the nth power: use the pow() function, accept the base and exponent, and return the exponent of the base. Use the shift operator (<<) to shift 1 to the left by the exponent number of places to calculate 10 raised to the power.
How to express 10 to the nth power in C language?
In C language, there are two ways to express 10 to the nth power:
Method 1: Use the pow() function
1 2 3 4 5 6 7 8 |
|
Method 2: Use the bit shift operator (<<)
1 2 3 4 5 6 |
|
Instructions:
Note:
n
is a non-negative integer. n
is too large, the pow()
function may return inf
(positive infinity) or nan
( non-numeric). n
, the bit-shift operator may be more efficient than the pow()
function. The above is the detailed content of How to express 10 to the nth power in C language. For more information, please follow other related articles on the PHP Chinese website!