Created
January 16, 2019 13:09
-
-
Save Bahaaib/2f42955de272b3b8a2dbb415cf9f7d79 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <iomanip> | |
| using namespace std; | |
| int gcd(int a, int b); | |
| long double lcm (long a, long b); | |
| int main() | |
| { | |
| int a = 0; | |
| int b = 0; | |
| cout << "Enter (a) and (b) respectively: " <<endl; | |
| cin >> a; | |
| cin.ignore(1, ' '); | |
| cin >> b; | |
| cout << "GCD: " << gcd(a, b) << endl; | |
| cout << "LCM: " << fixed << setprecision(0)<< lcm(a, b) << endl; | |
| return 0; | |
| } | |
| int gcd(int a, int b){ | |
| int a_rem = 0; | |
| if(b == 0){ | |
| return a; | |
| }else{ | |
| a_rem = a % b; | |
| gcd(b, a_rem); | |
| } | |
| } | |
| long double lcm(long a, long b){ | |
| long double mult =(long double) a * b; | |
| return mult / gcd(a, b); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment