本文介绍了完美的方形和完善立方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有在C ++中的任何predefined函数来检查的数量是否是方的任何数量和相同的立方体。
Is there any predefined function in c++ to check whether the number is square of any number and same for the cube..
推荐答案没有,但它很容易写一个:
No, but it's easy to write one:
bool is_perfect_square(int n) { if (n < 0) return false; int root(round(sqrt(n))); return n == root * root; } bool is_perfect_cube(int n) { int root(round(cbrt(n))); return n == root * root * root; }更多推荐
完美的方形和完善立方
发布评论