C++ Online Compiler
Example: C++ Program to Find LCM of Two Numbers using While loop
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// C++ Program to Find LCM of Two Numbers using While loop #include <iostream> using namespace std; int main() { int p, q, x; // p & q - To store the two positive numbers // x - To store the LCM number cout << "-----Enter the two positive integer numbers-----\n"; cin >> p >> q; x = p > q ? p : q; while (1) { if (x % p == 0 && x % q == 0) { cout << "\nThe LCM of the " << p << " and " << q << " numbers is " << x << ".\n"; break; } ++x; } return 0; }
110 150
Output
Clear
ADVERTISEMENTS