English

Write a program to find the LCM and GCD of two numbers.

Advertisements

Question

Write a program to find the LCM and GCD of two numbers.

Short/Brief Note
Advertisements

Solution

#include<iostream>
using namespace std;
int main ()
{
int a1, b1 lcm, gcd = 1, p;
cout<<"\n Enter 1st no:";
cin>>a1;
cout<<"\n Enter 2nd no:";
cin>>b1;
p = a1*b1;
for(int i = a1; j<=p; i++)
if(i%a1==0) && (i%b1==0)
{
1cm = i;
break;
}
cout<<"L.C.M.="<<1cm<<endl;
gcd = p/LCM;
cout<<"G.C.D="<<gcd;
cin.get();
return ();
}

shaalaa.com
Statements
  Is there an error in this question or solution?
Chapter 10: Flow of Control - Evaluation - Section - D [Page 179]
Advertisements
Share
Notifications



      Forgot password?
Use app×