首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >C++中的液晶显示模块程序

C++中的液晶显示模块程序
EN

Stack Overflow用户
提问于 2018-08-23 03:29:22
回答 2查看 352关注 0票数 -2
代码语言:javascript
运行
复制
#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相等时,不会打印任何内容。这个小问题的解决方案是什么?

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51973896

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档