Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    74
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Smile Mathematical operations in C+=

    Hi to you dear professional programmer!

    I have a question about Math in C++.

    you calculate the second root or "square" root of a number in C++ with sqrt or another function, or with pow(number, 0.5).

    How can I calculate the third root ("Cubic" root) of a number ?

    Will be so thankful to your helps.

  • #2
    Banned
    Join Date
    Jun 2007
    Location
    Web Designer
    Posts
    321
    Thanks
    0
    Thanked 6 Times in 6 Posts
    pow(number,1.0/3)

  • #3
    Regular Coder BrickInTheWall's Avatar
    Join Date
    Mar 2009
    Location
    Munich, Germany
    Posts
    139
    Thanks
    1
    Thanked 13 Times in 13 Posts
    third root of x is the same as x^(1/3) ...

  • #4
    New Coder
    Join Date
    Aug 2007
    Posts
    74
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Yes, I know math so good. But have you tested it ever in your own compiler ?

  • #5
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try
    Code:
    #include <stdio.h>
    #include<math.h>
    void main(){
    double x=27;
    
    printf("%lf ",pow(x,(double)1/3));
    }
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Quote Originally Posted by abduraooft View Post
    Try
    Code:
    #include <stdio.h>
    #include<math.h>
    void main(){
    double x=27;
    
    printf("%lf ",pow(x,(double)1/3));
    }
    Or

    Code:
    printf("%lf ",pow(x,1.0/3.0));
    OracleGuy


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •