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.$

Correct Answer: $C$

$\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.$

Correct Answer: $C$

- All categories
- General Aptitude 1.8k
- Engineering Mathematics 7.3k
- Digital Logic 2.9k
- Programming & DS 4.9k
- Algorithms 4.3k
- Theory of Computation 6k
- Compiler Design 2.1k
- Databases 4.1k
- CO & Architecture 3.4k
- Computer Networks 4.1k
- Non GATE 1.4k
- Others 1.4k
- Admissions 596
- Exam Queries 577
- Tier 1 Placement Questions 23
- Job Queries 72
- Projects 18

49,541 questions

54,071 answers

187,187 comments

70,978 users