cbrt() 函数原型
double cbrt( double arg );
cbrt() 函数接受一个参数(类型为 double),并返回其立方根(类型也为 double)。
[Mathematics] ∛x = cbrt(x) [In C Programming]
cbrt() 函数定义在 math.h 头文件中。
要查找 int
、float
或 long double
类型的立方根,您可以使用类型转换运算符显式将其转换为 double
。
int x = 0; double result; result = cbrt(double(x));
此外,您可以使用 cbrtf()
函数专门处理 float 类型,并使用 cbrtl()
处理 long double
类型。
long double cbrtl(long double arg ); float cbrtf(float arg );
示例:C cbrt() 函数
#include <stdio.h>
#include <math.h>
int main()
{
double num = 6, cubeRoot;
cubeRoot = cbrt(num);
printf("Cube root of %lf = %lf", num, cubeRoot);
return 0;
}
输出
Cube root of 6.000000 = 1.817121