English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C++ cbrt() function usage and example

C++ Library Function <cmath>

C ++The cbrt() function in returns the cube root of the number.

 ∛x = cbrt(x)

This function is in<cmath>defined in the header file.

cbrt() prototype [from C ++ 11[Standard begins]

double cbrt(double x);
float cbrt(float x);
long double cbrt(long double x);
double cbrt(T x); // For integral type

The cbrt() parameter

The cbrt() function takes a parameter to calculate its cube root.

The return value of cbrt()

The cbrt() function returns the cube root of the given parameter.

Example1How: cbrt() in C ++working in C?

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    double x = -1000.0, result;
    result = cbrt(x);
    cout << "-10The cube root of 00 is " << result << endl;
    return 0;
}

When running the program, the output is:

-10The cube root of 00 is -10

Example2: cbrt() function with integer parameter

#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    long x = 964353422;
    double result = cbrt(x);
    cout << "964353422The cube root is " << result << endl;
    return 0;
}

When running the program, the output is:

964353422The cube root is 987.974

C++ Library Function <cmath>