需要准备的材料分别有:电脑、C语言编译器.
①.、首先,打开C语言编译器,新建一个初始.cpp文件,例如:test.cpp.
double a = 1000, n = 10, p = 0.001;
printf("%lf", a * pow(1+p, n) - a);
①.,要加入头文件 math.h
例:
源代码如下:
#include"stdio.h"
#include"math.h"
main()
{
long total;
total = pow(x,y); /*调用pow函数*/
printf("%ld",total);
getch();
}
原型:extern float pow(float x, float y);
用法:#include math.h
功能:计算x的y次幂.
说明:x应大于零,返回幂指数的结果.
举例:
// pow.c
#include stdlib.h
#include math.h
#include conio.h
void main()
getchar();
相关函数:pow10
float
pow(float
x,
y);
pow(
double
y
);
头文件:math.h
返回值:x应大于零,返回幂指数的结果.
#include
int
main(void)
x
=
printf("%lf
raised
to
%lf
is
%lf\n",
y,
pow(x,
y));
return
0;
//
pow.c
clrscr();
clear
screen
textmode(0x00);
lines
per
LCD
pow()函数用来求x的y次幂,x、y及函数值都是double型 ,其原型为:double pow(double x, double y).
实例代码如下:
#includestdio.h
#includemath.h
printf("%f\n",pow(x, y));
return 0;
扩展资料:
在调用pow函数时,可能导致错误的情况:
如果底数 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.
参考资料:
pow函数——百度百科
以上就是土嘎嘎小编为大家整理的c语言幂函数pow的用法相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!