C 标准库 - <math.h>

C 语言 cbrt() 函数用于计算一个数的立方根

原型

double cbrt(double arg);

与 sqrt 不同,cbrt 对负数也有效(负数立方根仍为负数)。

参数

  • arg - 要求立方根的值(double)。

示例

#include <stdio.h>
#include <math.h>

int main() {
    printf("cbrt(27) = %.1f\n", cbrt(27));
    printf("cbrt(-8) = %.1f\n", cbrt(-8));
    return 0;
}

输出:

cbrt(27) = 3.0
cbrt(-8) = -2.0

注意事项

使用 math.h 的函数时,多数编译器需要链接数学库(编译选项 -lm)。