Ask Question
13 June, 08:01

Refer to the method f:

Public int f (int k, int n)

{

if (n = = k)

return k;

else

if (n > k)

return f (k, n - k);

else

return f (k - n, n);

}

What value is returned by the call f (6, 8) ?

+4
Answers (1)
  1. 13 June, 09:05
    0
    This function will land up in infinite function call

    Explanation:

    first time when the function gets invoked,

    f (6,8), so k=6 & n=8, inside the function it checks k==n, ie. 6==8, returns false, then one more if is available, so 6>8 is check for, once again it is false and else loop is executed, the function is called recursively using f (k-n, n), that is f (6-8,8), it means f (-2,8) is passed.

    Second time,

    if (-2==8) is false, so if (-2>8) is again false and function f (-10, 8) is called

    if (-10==8) is false, so if (-10>8) is again false and function f (-18,8) is called

    if (-18==8) is false, so if (-18>8) is again false and function f (-26,8) is called

    So this goes recursively and ends in an infinite function call.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Refer to the method f: Public int f (int k, int n) { if (n = = k) return k; else if (n > k) return f (k, n - k); else return f (k - n, n); ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers