首页 > 分享 > 3497. 水仙花数

3497. 水仙花数

最新推荐文章于 2024-09-20 20:19:17 发布

晨识草 于 2016-07-06 07:08:07 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

若三位数ABC满足ABC=A3+B3+C3,则称ABC为水仙花数. 例如153就是一个水仙花数. 编程找出100~999范围内的所有水仙花数.

代码实现:

// 水仙花数 #include<iostream> #include<cmath> using namespace std; int main() { int a, b, c; int result = 0; int num; int temp; for (int i = 100; i <= 999; ++i) { num = i; temp = i; a = num%10; num /= 10; b = num%10; num /= 10; c = num%10; if (a*a*a + b*b*b + c*c*c == temp) cout << temp << endl; } return 0; }

123456789101112131415161718192021222324

相关知识

水仙花数
打印“水仙花数”
C++: 水仙花数
打印水仙花数
3.水仙花数
水仙花数(调用函数)
n位水仙花数
水仙花数,C语言
999】中的水仙花数
c++中输出“水仙花数”

网址: 3497. 水仙花数 https://m.huajiangbk.com/newsview350261.html

所属分类:花卉
上一篇: C语言之水仙花数
下一篇: 输出所有的水仙花数,把谓水仙花数