Home >Backend Development >C#.Net Tutorial >How to express the nth power of x in C language
In C language, you can use the pow() function to calculate the nth power of x. Its syntax is: pow(double x, double y); it uses x as the base, y as the exponent, and returns x to the power of y.
In C language, the nth power of x represents
In C language, you can use the pow() function Calculates x raised to the nth power.
pow() function syntax
<code class="c">double pow(double x, double y);</code>
Parameter description
Return value
Returns the result of x raised to the power of y. If y is an integer, it returns the double type, otherwise it returns the long double type. .
Code example
<code class="c">#include <stdio.h> #include <math.h> int main() { double x, n; printf("请输入底数 x:"); scanf("%lf", &x); printf("请输入指数 n:"); scanf("%lf", &n); double result = pow(x, n); printf("x 的 n 次幂为:%.2f\n", result); return 0; }</code>
Output example
<code>请输入底数 x:5 请输入指数 n:3 x 的 n 次幂为:125.00</code>
The above is the detailed content of How to express the nth power of x in C language. For more information, please follow other related articles on the PHP Chinese website!