#include <iostream> #include<cmath> #include<ctime> #include<string> #include <iomanip> #include <fstream> using namespace std; int LCM(int n1, int n2); int main() { cout << "Enter first integer: "; int n1; cin >> n1; cout << "Enter second integer: "; int n2; cin >> n2; cout << "Least Common Multiple for " << n1 << " and " << n2 << " is " << LCM(n1,n2)<< endl; } int LCM(int n1, int n2) { int lcm = 1; int max = (n1 > n2) ? n1 : n2; while (true) { if (max % n1 ==0 && max % n2 == 0) { lcm = max; break; } else max++; } return lcm; // Return gcd }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter