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

modified LCM func. #17

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

chaitanya57
Copy link

works fine.!

@oyeb
Copy link
Member

oyeb commented Mar 10, 2016

Try 3$4. Or 6$7
[Errors]

@oyeb
Copy link
Member

oyeb commented May 6, 2016

You are tracking a temporary file ml_lcm.c~, never do that!
But that's not the issue, Your function "hangs" for the inputs I quoted. So I inspected the function, it's pretty clearly wrong.

for(i=a;;i++)
    {
        if(a%n1==0 && a%n2==0)
            return a;
    }

The loop variable is i but in the if, you test with a.
I suggest you use the well known LCM(a, b) = a*b/GCD(a, b). I believe that is an optimal solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants