Skip to content
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

lcm of two numbers #79

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 24 additions & 0 deletions lcm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <iostream>
using namespace std;

long long gcd(long long int a, long long int b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}

long long lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}

int main()
{
int a, b ;
cout<<"Enter a and b"<<endl;
cin>>a>>b;
cout <<"LCM of " << a << " and "
<< b << " is " << lcm(a, b);
return 0;
}
Binary file added lcm.exe
Binary file not shown.