#include<iostream>
      using namespace std;
      int main()
      {
      	int fnum,snum,gcd,lcm;
      	cout<<"Enter first number";
      	cin>>fnum;
      	cout<<"\nEnter second number";
      	cin>>snum;
      	//find factors of both numbers
      	for(int i=1;i<=fnum && i<=snum;i++)
      	{
      		if(fnum%i==0 && snum%i==0)
      			gcd=i;
      	}
      	//find lcm of both numbers
      	lcm = fnum*snum/gcd;
      	cout<<"\n GCD of given numbers is:"<<gcd;
      	cout<<"\n LCM of given numbers is:"<<lcm;
      	return 0;
      }
      
      Cpp language logo

      LCM

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.