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

+16 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$

+25 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.3k
- Engineering Mathematics 5.4k
- Digital Logic 2.1k
- Programming & DS 3.9k
- Algorithms 3.4k
- Theory of Computation 4.2k
- Compiler Design 1.6k
- Databases 3.1k
- CO & Architecture 2.7k
- Computer Networks 3.1k
- Non GATE 1.1k
- Others 1.4k
- Admissions 501
- Exam Queries 447
- Tier 1 Placement Questions 19
- Job Queries 62
- Projects 12

37,939 questions

45,453 answers

131,190 comments

48,206 users