C语言调用pow( )函数实现幂运算

在我们写代码时,会经常要求幂运算。虽说不是很复杂,但是有又快又省事的库函数为啥不用呢?
函数原型double pow(double x, double y)
函数功能:x的y次方
头文件:#include <cmath >或 #include <math.h>

示例:

#include <stdio.h>
#include <cmath>	//或#include <math.h> 

int main()
{
    
    
	printf("%d",(int)pow(2,3));
    return 0;
}

在这里插入图片描述
ps: 因为pow( )函数的返回值为double类型,故printf打印格式为%f或%lf,或者像示例一样先转为int类型,否则将输出0。

参考博客:https://blog.csdn.net/snowcatvia/article/details/96639110

猜你喜欢

转载自blog.csdn.net/m0_51336041/article/details/121215810
今日推荐