Unless you tell what is starting point , how can we tell where recursion stops ?

The Gateway to Computer Science Excellence

First time here? Checkout the FAQ!

x

+17 votes

What value would the following function return for the input $x=95$?

Function fun (x:integer):integer; Begin If x > 100 then fun = x – 10 Else fun = fun(fun (x+11)) End;

- $89$
- $90$
- $91$
- $92$

+26 votes

Best answer

Value returned by $\text{fun}(95) = \text{fun}(\text{fun}(106))$

$\qquad\qquad= \text{fun}(96)$

$\qquad\qquad= \text{fun}(\text{fun}(107))$

$\qquad\qquad= \text{fun}(97)$

$\qquad\qquad= \text{fun}(\text{fun}(108))$

$\qquad\qquad= \text{fun}(98)$

$\qquad\qquad = \text{fun}(\text{fun}(109))$

$\qquad\qquad= \text{fun}(99)$

$\qquad\qquad= \text{fun}(\text{fun}(110))$

$\qquad\qquad= \text{fun}(100) $

$\qquad\qquad= \text{fun}(\text{fun}(111)) $

$\qquad\qquad= \text{fun}(101) = 91.$

$\qquad\qquad= \text{fun}(96)$

$\qquad\qquad= \text{fun}(\text{fun}(107))$

$\qquad\qquad= \text{fun}(97)$

$\qquad\qquad= \text{fun}(\text{fun}(108))$

$\qquad\qquad= \text{fun}(98)$

$\qquad\qquad = \text{fun}(\text{fun}(109))$

$\qquad\qquad= \text{fun}(99)$

$\qquad\qquad= \text{fun}(\text{fun}(110))$

$\qquad\qquad= \text{fun}(100) $

$\qquad\qquad= \text{fun}(\text{fun}(111)) $

$\qquad\qquad= \text{fun}(101) = 91.$

- All categories
- General Aptitude 1.5k
- Engineering Mathematics 7.1k
- Digital Logic 2.7k
- Programming & DS 4.9k
- Algorithms 4.2k
- Theory of Computation 5.3k
- Compiler Design 2.1k
- Databases 4k
- CO & Architecture 3.5k
- Computer Networks 4k
- Non GATE 1.4k
- Others 1.5k
- Admissions 559
- Exam Queries 553
- Tier 1 Placement Questions 23
- Job Queries 69
- Projects 18

47,913 questions

52,293 answers

182,250 comments

67,738 users