Home » C++ programming language

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 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.

Example:

    Input:
    int x = 2;

    Function call:
    cbrt(x);

    Output:
    1.25992

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

// 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

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.