用pow函数求a的3次方(a为实数)以下这段代码为什么不对?#include #include fl

发布时间:2021-02-25 10:08:35

用pow函数求a的3次方(a为实数)以下这段代码为什么不对?#include #include fl

网友回答

#include
#include
float pow(float x,int y);
int main()
{ float a,product;
printf(please input value of a:);
scanf(%f,&a);
product=pow(a,3);
printf(\ncube of %.4f is%.4f\n\n,a,product); //这里缺少一个 a
system(PAUSE);
return 0;
}float pow(float x,int y)
{ int p; for(p=1;y>0;y--)
p*=x; return((float)p); //这里强制转换一下就可以了
}
以上问题属网友观点,不代表本站立场,仅供参考!