Saved Bookmarks
| 1. |
Write a program to find the LCM and GCD of two numbers. |
|
Answer» #include<iostream> using namespace std; int main() { int a1,b1 1cm,gcd = 1,p; cout<<"/n Enter 1 st no:"; cin>>a1; cout<<"/n Enter 2 nd no:"; cin>>b1; p = a1*b1; for(int i = a1; i<= p; i++) if(i%a1 == 0)&&(i%b1 == 0) { 1 cm = i; break; } cout<<"L.C.M = "<<1cm<<end1; gcd=p/LCM; cout<<"G.C.D="<<gcd; cin.get(); return 0; } |
|