How can I obtain the cube root in C++?

后端 未结 8 1962
你的背包
你的背包 2020-12-09 02:12

I know how to obtain the square root of a number using the sqrt function.

How can I obtain the cube root of a number?

8条回答
  •  一向
    一向 (楼主)
    2020-12-09 02:59

    I would discourage any of the above methods as they didn't work for me. I did pow(64, 1/3.) along with pow(64, 1./3.) but the answer I got was 3
    Here's my logic.

    ans = pow(n, 1/3.);
    if (pow(ans, 3) != n){
       ans++;
    }
    

提交回复
热议问题