How to express the cubic root of a variable?

Status
Not open for further replies.

Fabyfakid

Baseband Member
Messages
60
Need help; trying to get the cubic root of a variable which I have declared as a defined integer, and getting a value of 0. What could I be doing wrong?

doing this:

int x = "number I want";
pow(x, (1/3));


Thanks in advanced for your help
 
What language are you using? Try 1.0 instead of just 1 to force the result of the division to be a floating point number. For instance, in C#
Code:
int x = 8;  // find the cube root of x, which should be 2

// This returns the wrong result because it uses integer division
Math.Pow(x, 1/3);

// This returns the correct result because it uses floating point division
Math.Pow(x, 1.0/3);
 
My suggestion still works for C. Try this:

Code:
#include <math.h>
#include <stdio.h>

int main(){
    int x = 8;
    double y = -1;

    y = pow(x, 1.0/3);
    printf("%f", y);
    
    return 0;
}
 
Status
Not open for further replies.
Back
Top Bottom