完美的方形和完善立方

编程入门 行业动态 更新时间:2024-10-27 01:36:17
本文介绍了完美的方形和完善立方的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有在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; }

更多推荐

完美的方形和完善立方

本文发布于:2023-11-23 09:00:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620854.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:立方   方形   完美

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!