Skip to content

modified LCM func.#17

Open
chaitanya57 wants to merge 4 commits intotechknowclub:masterfrom
chaitanya57:master
Open

modified LCM func.#17
chaitanya57 wants to merge 4 commits intotechknowclub:masterfrom
chaitanya57:master

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

Comments