C++ cbrt() 函数 使用方法及示例
C ++中的cbrt()函数返回数字的立方根。
∛x = cbrt(x)
此函数在<cmath>头文件中定义。
cbrt()原型[从C ++ 11标准开始]
double cbrt(double x); float cbrt(float x); long double cbrt(long double x); double cbrt(T x); // For integral type
cbrt()参数
cbrt()函数采用一个要计算其立方根的参数。
cbrt()返回值
cbrt()函数返回给定参数的立方根。
示例1:cbrt()如何在C ++中工作?
#include <iostream> #include <cmath> using namespace std; int main() { double x = -1000.0, result; result = cbrt(x); cout << "-1000 的立方根是 " << result << endl; return 0; }
运行该程序时,输出为:
-1000的立方根是 -10
示例2:带有整型参数的cbrt()函数
#include <iostream> #include <cmath> using namespace std; int main() { long x = 964353422; double result = cbrt(x); cout << "964353422的立方根是 " << result << endl; return 0; }
运行该程序时,输出为:
964353422的立方根是 987.974