Skip to content

Instantly share code, notes, and snippets.

@Bahaaib
Created January 16, 2019 13:09
Show Gist options
  • Select an option

  • Save Bahaaib/2f42955de272b3b8a2dbb415cf9f7d79 to your computer and use it in GitHub Desktop.

Select an option

Save Bahaaib/2f42955de272b3b8a2dbb415cf9f7d79 to your computer and use it in GitHub Desktop.
#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