C++ 最小公倍数

    科技2024-06-22  73

    #include <iostream> using namespace std; int main() { int n1, n2, max; cout << "输入两个数: "; cin >> n1 >> n2; // 获取最大的数。n1>n2 就取n1 max = (n1 > n2) ? n1 : n2; do //死循环 {//如果 最大值 取余 n1和n2 都为0 if (max % n1 == 0 && max % n2 == 0) {//打印出最小公倍数 cout << "LCM = " << max; break;//结束循环 } else//否则,最大值+1 ++max; } while (true); system("pause"); return 0; }

    Processed: 0.009, SQL: 8