×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

cbrt() function with example in C++

C++ cbrt() function: Here, we are going to learn about the cbrt() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on April 26, 2019

C++ cbrt() function

cbrt() function is a library function of cmath header, it is used to find the cubic root of a given number, it accepts a number and returns the cubic root.

Syntax

Syntax of cbrt() function:

cbrt(x);

Parameter(s)

x – a number whose cubic root to be calculated.

Return value

double – it returns double value that is the cubic root of the given number x.

Sample Input and Output

Input:
int x = 2;

Function call:
cbrt(x);

Output:
1.25992

Example

// C++ code to demonstrate the example of 
// cbrt() function

#include <iostream>
#include <cmath>
using namespace std;

// main code section
int main()
{
    float x;
    
    //input the value
    cout<<"Enter a number: ";
    cin>>x;

    // calculate the square root
    float result = cbrt(x);
    cout<<"cubic root of "<<x<<" is = "<<result;
    cout<<endl;
    
    return 0;
}

Output

First run:
Enter a number: 10 
cubic root of 10 is = 2.15443 

Second run:
Enter a number: 123.45 
cubic root of 123.45 is = 4.97925 

Third run:
Enter a number: 0
cubic root of 0 is = 0

Fourth run:
Enter a number: -1234
cubic root of -1234 is = -10.726 


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.