C++ program to find LCM of two numbers














































C++ program to find LCM of two numbers



Problem statement :
      Two positive integer are given , find LCM of two numbers and print it. 

C++ program to find LCM of two numbers

#include <bits/stdc++.h>
using namespace std ; int main() { int n1, n2, max; cout<<"Enter two positive integers: "; cin>>n1>>n2; // maximum number between n1 and n2 is stored in max if( n1 > n2 ) max = n1; else max=n2; while (1) { if (max % n1 == 0 && max % n2 == 0) { cout<<"The LCM of "<< n1 <<" and " << n2 << " is " << max ; break; } max++; } return 0; }

Output :

Enter two positive integers: 20 25

The LCM of 20 and 25 is 100


Comments