
2,
书写格式:Power(Number,Power)。其中Number表示底数,Power表示幂值。
如2的10次方,可以写为:POWER(2,10)
#include <iostream>
using namespace std
double power(double x, int n)
{
double val = 1.0
while (n--)
val *= x
return val
}
int main()
{
double pow
pow = power(5, 2)
cout <<"5 to the power 2 is:" <<pow <<'\n'
return 0
},
3,语法:POWER(<number>, <power>)
4,,number
可以为任意实数的底数。
power
对底数进行幂运算的指数。
5,返回值:小数。
pow函数:
C/C++中的数学函数;
pow() 函数用来求 x 的 y 次幂(次方),x、y及函数值都是double型
pow()用来计算以x 为底的 y 次方值,然后将结果返回。设返回值为 ret,则 ret = xy。
可能导致错误的情况:
如果底数 x 为负数并且指数 y 不是整数,将会导致 domain error 错误。
如果底数 x 和指数 y 都是 0,可能会导致 domain error 错误,也可能没有;这跟库的实现有关。
如果底数 x 是 0,指数 y 是负数,可能会导致 domain error 或 pole error 错误,也可能没有;这跟库的实现有关。
如果返回值 ret 太大或者太小,将会导致 range error 错误。
错误代码:
如果发生 domain error 错误,那么全局变量 errno 将被设置为 EDOM;
如果发生 pole error 或 range error 错误,那么全局变量 errno 将被设置为 ERANGE。
拓展资料:
原型:在TC2.0中原型为extern float pow(float x, float y),而在VC6.0中原型为double pow( double x, double y )
头文件:math.h/cmath(C++中)
功能:计算x的y次幂。
返回值:x不能为负数且y为小数,或者x为0且y小于等于0,返回幂指数的结果。
返回类型:double型,int,float会给与警告!百度百科--POW函数
返回给定数字的乘幂。
POWER函数的主要作用是返回给定数字的乘幂。
函数定义:
POWER(number,power)
POWER(底数,指数)
参数说明:
Number:底数,可以为任意实数。
Power:指数,底数按该指数次幂乘方。
扩展资料:
数据公式:
#include <iostream>using namespace stddouble power(double x, int n)
{double val = 1.0while (n--)val *= xreturn val}int main()
{double powpow = power(5, 2)out <<"5 to the power 2 is:" <<pow <<'\n'return 0}
参考资料来源:百度百科-power
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)