do..while ループ for: list を使用してプログラムを作成しようとして
います。
1 に答える
1
このコードは機能するはずです。私はそれをテストしたり、時間を測定したりしていません。おそらく、速度を向上させるためのより良い方法がありますが、次のとおりです。
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)
また、これについて学ぶ必要がある場合は、 do...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;
}
于 2011-12-17T22:10:31.330 に答える