Skip to content

Added the code for hcf and lcm of two number in c++ using recursion #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Mathematics/GCD/gcdlcm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def gcd(a,b):
if a == 0:
return b
return gcd(b % a, a)

# Function to return LCM of two numbers
def lcm(a,b):
return (a / gcd(a,b))* b

# Driver program to test above function
a = 15
b = 20
print('LCM of', a, 'and', b, 'is', lcm(a, b))
print('GCD of', a, 'and', b, 'is', gcd(a, b))
42 changes: 42 additions & 0 deletions Mathematics/GCD_LCM.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define l long
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}

// Function to return LCM of two numbers
ll lcm(ll a, ll b)
{
return (a / gcd(a, b)) * b;
}

// Driver program to test above function
int main()
{
ll a,b;
cin>>a>>b;
cout <<"GCD of " << a << " and "
<< b << " is " << gcd(a, b);
cout <<"LCM of " << a << " and "
<< b << " is " << lcm(a, b);
return 0;
}