fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n1, n2, max;
  7.  
  8. cout << "Enter two numbers:";
  9. cin >> n1 >> n2;
  10.  
  11. // maximum value between n1 and n2 is stored in max
  12. max = (n1 > n2) ? n1 : n2;
  13.  
  14. do
  15. {
  16. if (max % n1 == 0 && max % n2 == 0)
  17. {
  18. cout << "LCM =" << max;
  19. break;
  20. }
  21. else
  22. ++max;
  23. }while(true);
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 5316KB
stdin
23
89
stdout
Enter two numbers:LCM =2047