Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int GreatestCommonDivisor(int x,int y);
- int LeastCommonMultiple(int x,int y);
- void Menu();
- int main ()
- {
- int a,b,c;
- do
- {
- Menu();
- cin>>c;
- system("CLS");
- switch (c)
- {
- case 1:
- cout<<"Insert New Numbers"<<endl;
- cin>>a>>b;
- break;
- case 2:
- cout<<"Lcm="<<LeastCommonMultiple(a,b)<<endl;
- break;
- case 3:
- cout<<"Gcd="<<GreatestCommonDivisor(a,b)<<endl;
- break;
- case 4:
- cout<<"The Program Is Closing"<<endl;
- system("PAUSE");
- break;
- default:
- cout<<"Wrong Character"<<endl;
- break;
- }
- }while (c!=4);
- return 0;
- }
- int GreatestCommonDivisor(int x,int y)
- {
- int m;
- while (y!=0)
- {
- m=x%y;
- x=y;
- y=m;
- }
- return x;
- }
- int LeastCommonMultiple(int x,int y)
- {
- int lcm;
- lcm=x*y;
- lcm=lcm/GreatestCommonDivisor(x,y);
- return lcm;
- }
- void Menu()
- {
- cout<<"Menu:"<<endl
- <<"1. New numbers."<<endl
- <<"2. Calculation of lcm."<<endl
- <<"3. Calculation of gcd."<<endl
- <<"4. Exit."<<endl;
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement