what wud happen if we call gcd(m,n) with m positive nd n negative in the following definition | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

what wud happen if we call gcd(m,n) with m positive nd n negative in the following definition

def gcd(m,n) : if m < n : (m,n) = (n,m) if (m%n) == 0 : return (n) else : diff = m-n return (gcd(max(n,diff),min(n,diff))) a) the function would still compute gcd correctly b) the function would not terminate c) the behavior depends on the exact values of m and n give reason for ur answer

22nd Jul 2016, 7:09 PM
Vipul Jain
Vipul Jain - avatar
1 Answer
0
"c" since m and n aren't defined yet. everything in the else statement is run since none of them is True (btw, you need to use 'elif'). So you would probably get a exception (NameError)
26th Jul 2016, 9:17 AM
Tom Post
Tom Post - avatar