c语言pow怎么计算次幂

1095
2024/5/4 14:24:07
栏目: 编程语言
开发者测试专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在C语言中,可以使用pow()函数来计算次幂。该函数需要包含<math.h>头文件。

例如,要计算2的3次幂,可以使用以下代码:

#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()函数计算次幂了。

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

推荐阅读: C语言怎么实现图书管理系统