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