C++ Power用法及代码示例

您所在的位置:网站首页 power函数属于什么 C++ Power用法及代码示例

C++ Power用法及代码示例

2024-01-04 02:39| 来源: 网络整理| 查看: 265

给定两个基数和 index ,pow()函数找到x升为y的幂的函数,即xy。本质上以C表示的 index 是使用pow()函数计算的。 例:

Input: 2.0, 5.0 Output: 32 Explanation: pow(2.0, 5.0) executes 2.0 raised to the power 5.0, which equals 32 Input: 5.0, 2.0 Output: 25 Explanation: pow(5.0, 2.0) executes 5.0 raised to the power 2.0, which equals 25

用法:

double pow(double x, double y);

参数:该方法有两个参数:

x:浮点基值 y:浮点功率值

程序:

C // C program to illustrate // power function #include #include    int main() {     double x = 6.1, y = 4.8;        // Storing the answer in result.     double result = pow(x, y);     printf("%.2lf", result);        return 0; } C++ // CPP program to illustrate // power function #include using namespace std;    int main() {     double x = 6.1, y = 4.8;        // Storing the answer in result.     double result = pow(x, y);        // printing the result upto 2     // decimal place     cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3