std::cbrt() in C++
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.
Syntax:
// 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. cbrt(num)
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.
Examples:
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; } |
Output:
2.08008 1.9229
Recommended Posts:
- Nested Loops in C++ with Examples
- _Find_first() function in C++ bitset with Examples
- _Find_next() function in C++ bitset with Examples
- Left-Right traversal of all the levels of N-ary tree
- Difference between Iterators and Pointers in C/C++ with Examples
- ostream::seekp(pos) method in C++ with Exmaples
- Default Methods in C++ with Examples
- C++ Tutorial
- Hello World Program : First program while learning Programming
- Difference between Argument and Parameter in C/C++ with Examples
- <cfloat> float.h in C/C++ with Examples
- C/C++ #include directive with Examples
- C/C++ if else statement with Examples
- C/C++ if statement with Examples
- C/C++ do while loop with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.