Perfect square and perfect cube

前端 未结 8 2136
离开以前
离开以前 2020-12-09 12:27

Is there any predefined function in c++ to check whether the number is square of any number and same for the cube..

8条回答
  •  爱一瞬间的悲伤
    2020-12-09 12:54

    For perfect square you can also do:

    if(sqrt(n)==floor(sqrt(n)))
        return true;
    else
        return false;
    

    For perfect cube you can:

    if(cbrt(n)==floor(cbrt(n)))
        return true;
    else
        return false;
    

    Hope this helps.

提交回复
热议问题