#include <iostream>
using std::cout;
using std::cin;
int main()
{
int num1 = 0;
int num2 = 0;
cout << "Please enter two numbers (remember to put
a space between them):\n";
cin >> num1 >> num2;
const int num_limit = num1 * num2;
for (int i = 1; i <= num_limit; i++)
{
int product = num1 * i;
int product2 = num2 * i;
// test for when multiples are equal
if (product == product2)
{
cout << "The LCM of " << num1 << " and " <<
num2 << " is: ";
}
}
}我尝试从用户输入的两个整数中获取LCM。for循环中的if语句没有执行我希望它做的事情,因为当product和product2相等时,不会打印任何内容。这个小问题的解决方案是什么?
https://stackoverflow.com/questions/51973896
复制相似问题