我想用do..while循环写出一个程序:列出100个向下可分的7和5但不是11的所有数字。
你能帮我吗?C do-while循环
回答
此代码应该工作,我没有测试过或超时并有可能这样做明智的速度更好的办法,但:
int counter = 0;// Counts the index of the array
int num = 100;// the iterator like 'i' in a for loop
int nums [100];// the array to store all the numbers
do {
if (num % 7 == 0 && num % 5 == 0 && num % 11 != 0) {
nums[counter] = num;
counter++;
}
num--;
} while(num >= 0)
另外这里是关于做一些东西的页面。 ..while如果你只需要学习一下吧:
http://www.keil.com/support/docs/1950.htm
编辑(sehe)我不能让我的努力工作去浪费,可我:
对于绝对的乐趣和踢腿,这里是C++ 0x中我pythonist响应
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
#include <boost/phoenix/phoenix.hpp>
#include <iostream>
using boost::adaptors::filtered;
using boost::phoenix::arg_names::arg1;
using boost::irange;
int main(int argc, const char *argv[])
{
for (auto i : irange(200,1,-1) |
filtered(!((arg1 % 5) | (arg1 % 7)) && (arg1 % 11)))
std::cout << i << std::endl;
}
为什么sehe在我的文章中提到?我不认为这是有道理的,我不明白它是如何进入我的帖子 – annonymously 2011-12-17 22:40:49
顺便说一句,这等于'num%35 == 0 && num%11!= 0'因为5和7是素数。 – MByD 2011-12-17 23:10:00
那么这会让我很难理解我在做什么 – annonymously 2011-12-17 23:11:07
- 1. 在While循环中变换doWhile
- 2. For循环C#不循环
- 3. C++:在循环
- 4. C++:在循环
- 5. C#为循环
- 6. C#循环
- 7. C#foreach循环
- 8. C++循环宏
- 9. for循环C++
- 10. 将循环转换为while循环c#
- 11. C++ for循环转换为while循环
- 12. C#的循环内部循环#
- 13. 目标c循环
- 14. 循环链表C
- 15. C++嵌套循环
- 16. C#循环问题
- 17. 在C++ while循环
- 18. C# - 嵌套循环
- 19. for循环Objective-C
- 20. 在C#中循环?
- 21. C++异步循环
- 22. C循环依赖
- 23. C++:CIN while循环
- 24. C++ do-while循环
- 25. C++怪异循环
- 26. C++循环映射
- 27. C#在vb.net循环
- 28. 停止循环C#?
- 29. C#循环编号
- 30. C++概念循环
你是否介意我们你有什么尝试? – MByD 2011-12-17 22:02:50
这是一项家庭作业吗?如果是,请添加标签。 – dasblinkenlight 2011-12-17 22:02:58
请1)向我们展示您的代码到目前为止的“do/while”循环2)问:如何判断一个数是否可以被7整除?可以被5整除?可以被5和7整除?提示:您是否熟悉“%”运算符? – paulsm4 2011-12-17 22:13:27