C语言中power函数的用法是什么

509
2023/10/1 20:29:11
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C语言中,power函数用于计算一个数的幂。

函数原型为:

double pow(double x, double y);

参数x是底数,参数y是指数。函数返回x的y次方的结果。

示例代码:

#include <stdio.h>
#include <math.h>
int main() {
double base = 2.0;
double exponent = 3.0;
double result = pow(base, exponent);
printf("%f raised to the power of %f is %f\n", base, exponent, result);
return 0;
}

输出结果:

2.000000 raised to the power of 3.000000 is 8.000000

在上面的示例中,pow函数计算了2的3次方,得到了8的结果。

辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读: c语言怎么使用函数计算两点间距离