C cbrt()

cbrt() 函数原型

double cbrt( double arg );

cbrt() 函数接受一个参数(类型为 double),并返回其立方根(类型也为 double)。

[Mathematics]  ∛x = cbrt(x) [In C Programming]

cbrt() 函数定义在 math.h 头文件中。


要查找 intfloatlong 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
你觉得这篇文章有帮助吗?

我们的高级学习平台,凭借十多年的经验和数千条反馈创建。

以前所未有的方式学习和提高您的编程技能。

试用 Programiz PRO
  • 交互式课程
  • 证书
  • AI 帮助
  • 2000+ 挑战