【C语言】pow函数的模拟实现(递归) |
您所在的位置:网站首页 › c语言中pow函数 › 【C语言】pow函数的模拟实现(递归) |
一、库函数——pow函数功能介绍与使用演示
1.API文档中的解释 (1)功能:Calculates x raised to the power of y.即计算x的y次方 (2)参数: base:Base value.即基数 exponent:Exponent value.即指数 (3)返回值:pow returns the value of xy. No error message is printed on overflow or underflow即Pow返回xy的值。溢出或下溢时不会打印错误消息。 (4)头文件: (5)兼容性:ANSI, Win 95, Win NT (6)摘要 :The pow function computes x raised to the power of y. 即pow函数计算x的y次方 pow does not recognize integral floating-point values greater than 264, such as 1.0E100.即pow不能识别大于264的整型浮点值,例如1.0E100。 2.pow函数使用演示 #include #include int main() { double x = 2.0, y = 3.0, z; z = pow( x, y ); printf( "%.1f to the power of %.1f is %.1f\n", x,y,z); return 0; } 二、pow函数的模拟实现实现思路: #include double Pow(int n,int k) { if (k > 0) return n * Pow(n, k - 1); else if (k == 0) return 1; else return 1.0 / Pow(n, -k); } int main() { int n ,k; scanf("%d%d", &n,&k); double ret = Pow(n, k); printf("%.2lf\n",ret); return 0; } 三、补充1.API 文档是什么? 简单来说它就是 对所有 API 的调用和其中涉及到的参数的清晰的解释说明 。. 说具体一点,就是每个 API 可以做什么,以及对 API 中每个参数的解释,包括它们的类型、格式、可能的取值、验证规则、是否必需等。 参考: https://zhuanlan.zhihu.com/p/36729484#:~:text=API 2.模拟实现中自定义函数的命名建议 通过大小写字母的变化进行区分,最好不要和库函数的命名冲突。 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |