求水仙花数
来源:互联网 发布:linux mount 原理 编辑:程序博客网 时间:2024/06/06 06:34
题目:
水仙花数是一个十进制数的各个位的三次方之和等于其本身。
ifFlower()函数用来判断该数是不是水仙花数。
这个程序是输入两个整数m, n.
打印出m n之间的水仙花数,如果没有,就输出no
#include <iostream>#include <vector>using namespace std;bool isFlower(int num){ bool flag = false; int sum = 0; int a = num; while(a) { int temp; temp = a %10; a = a / 10; sum += temp * temp * temp; } if (sum == num) flag = true; else flag = false; return flag;}int main(void){ vector<bool> nums(1000, 0); for(int i = 100; i < 1000; ++i) { if (isFlower(i)) { nums[i] = true; } else { nums[i] = false; } } int m, n; while(cin >> m >> n) { bool cout_flag = false; for (int i = m; i <=n; ++i) { if (nums[i] == true) { cout << i << " "; cout_flag = true; } } cout << endl; if (cout_flag == false) cout << "no" << endl; } return 0;}
0 0
- 求水仙花数
- 求水仙花数
- 求水仙花数
- 求水仙花数
- 求水仙花数
- 求所有水仙花数
- 求水仙花数
- 求水仙花数
- 求水仙花数
- 求水仙花数
- C#求水仙花数!
- 求水仙花数
- 求水仙花数。
- #DayTwo#,求水仙花数
- 求水仙花数的
- 求水仙花数
- 求水仙花数
- 求水仙花数
- iOS应用架构谈 开篇
- RESTful 详解
- 单链表--游标实现
- CSS 混合布局
- 合并两张bitmap ANDROID
- 求水仙花数
- UITextField 详解
- Java设计模式之代理模式(动态代理-基础篇)
- 【解决方案】Command failed due to signal: Segmentation fault: 11
- iOS应用架构谈 view层的组织和调用方案
- servlet向客户端发送数据(PrintWriter ,ServletOutputStream)
- 关于webView上的长按保存照片的那些事
- div的width和height属性
- 初学Java1_Eclipse的简单使用