Advertisement
keymasterviriya1150

Untitled

Sep 8th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.42 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int n1, n2, max;
  6.     cout << "Enter two numbers: ";
  7.     cin >> n1 >> n2;
  8.    
  9.     max = (n1 > n2) ? n1 : n2; // maximum value between n1 and n2 is stored in max
  10.  
  11.     do {
  12.         if (max%n1 == 0 && max%n2 == 0) {
  13.             cout << "LCM = " << max;
  14.             break;
  15.         }
  16.         else
  17.             ++max;
  18.     }
  19.     while (true);
  20.    
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement