1
这是我的代码来查找数字的倍数。但它不输出倍数。为什么这个简单的循环不起作用?
#include <iostream>
using namespace std;
int main()
{
cout << "Enter the number:" << endl;
int num;
cin >> num;
for (int i = 1; i == num; i++) {
if ((num % i) == 0) {
int res = num/i;
cout << num << " divided by " << i << "=" << res << endl;
}
}
return 0;
}
因为我== num表示,而我== NUM和你的意思是我
for循环中间的条件不是结束条件,而是运行循环中下一轮的条件。如果它是假的,则循环停止。 –