For a given set of numbers, the LCM is the smallest number that is a multiple of every one of the numbers
C++ program to find LCM.
#include <iostream>
using namespace std;
int main() {
    int a,b,r,lcm;
    cout<<"Enter Two Numbers(First Number Should be big) : ";
    cin>>a>>b;
    while(1)
    {
        lcm=r;
        r=a%b;
        if(r==0)
            break;
        else
            a*=2;
    }
    cout<<"LCM Is : "<<a;
    return 0;
}Output :
 
 
No comments:
Post a Comment