Skip to content

Commit 18367c3

Browse files
authored
Create gcd and lcm
Gives greatest common divisor and least common multiple of 2 numbers.
1 parent 4d2eef2 commit 18367c3

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

gcd and lcm

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
long long gcd(int a, int b)
5+
{
6+
if (a == 0)
7+
return b;
8+
return gcd(b % a, a);
9+
}
10+
11+
int main()
12+
{
13+
long long a, b;
14+
cin>>a>>b;
15+
long long g = gcd(a, b);
16+
cout<<"GCD = "<<g<<endl;
17+
cout<<"LCM = "<<(a*b)/g;
18+
return 0;
19+
}

0 commit comments

Comments
 (0)