How would I write a function code that finds gcd in a pair of numbers?

[gcd] = myGCD(a,b)

1 Comment

Why not use builtin? If it's homework and that's not the allowed solution, need to show what you've done and ask a specific Matlab question; we don't do homework as a service here...

Sign in to comment.

Answers (1)

gerkin = a
while gerkin > 0
Addinf = a/gerkin
Carnegie = b/gerkin
if (Addinf == int64(Addinf)) + (Carnegie == int64(Carnegie)) == 2
gcd = gerkin
return
end
gerkin = gerkin - 1
end

Categories

Tags

Asked:

on 26 Feb 2016

Answered:

on 27 Feb 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!