Skip to content
Related Articles

Related Articles

Improve Article

std::cbrt() in C++

  • Difficulty Level : Basic
  • Last Updated : 27 Jan, 2021

The std::cbrt() is an inbuilt function in C++ STL which is used to calculate the cube root of number. It accepts a number as argument and returns the cube root of that number.

// Returns cube root num (num can be
// of type int, double, long double or
// long long type.
// The return type is same as parameter
// passed.

Parameter: The parameter can be of int, double, long double or long long type.
Return Value: It returns the cube root of the number num. The datatype of returned cube root is same as that of the parameter passed except when an integer is passed as parameter. If the parameter passed is integral then the cbrt() function will return a value of type double

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
Input : 8
Output : 2 

Input : 9
Output : 2.08008

Below program illustrate the cbrt() function: 


// CPP program to demonstrate the cbrt()
// STL function
#include <bits/stdc++.h>
using namespace std;
int main()
    // cbrt() function with integral
    // argument
    int num1 = 9;
    cout << cbrt(num1) << endl;
    // cbrt() function with floating-point
    // argumetnt
    double num2 = 7.11;
    cout << cbrt(num2) << endl;
    long long num3 = 7;
    cout << cbrt(num3);
    return 0;




My Personal Notes arrow_drop_up
Recommended Articles
Page :