C语言在库函数中提供了一个计算乘方的函数
函数名为pow
函数头文件为 math.h
函数的原型为double pow (double x,double y)
函数的功能为计算 x^y的值,并返回结果
C语言的乘方运算可以利用库函数pow。
pow函数原型:double pow( double x, double y )
头文件:math.h/cmath(C++中)
功能:计算x的y次幂。
参考代码:
#include <stdio.h>#include <math.h>
int main()
{
int a=3,b=2
double t = pow(a,b)//计算3的平方并输出
printf("%.0lf\n",t)
return 0
}
/*
输出:
9
*/