GATE CSE
First time here? Checkout the FAQ!
x
+4 votes
54 views

Consider the recursive function $\mathsf{mc91}$.

int mc91(int n)
{
    print n
    if (n > 100) {
            return n-10;
    }
    else {
        return mc91(mc91(n+11));
    }
}

Let 

$\mathsf{Out}=\{n : \text{ there is an } x \in \{0, 1, \dots , 100 \} \text{ such that } n \text{ is one of the integers printed by } \mathsf{mc91}(x)\}$

Then which of the following is $\mathsf{Out}$?

  1. $\{ n:  - \infty < n \leq 100 \}$
  2. $\{ n:  0 \leq n \leq 101 \}$
  3. $\{ n:  0 \leq n \leq 110 \}$
  4. $\{ n:  0 \leq n \leq 111 \}$
  5. $\{ n:  0 \leq n < + \infty \}$
asked in Others by Veteran (92.5k points) 957 2314 3109 | 54 views

1 Answer

+3 votes
Best answer

 

For using the values of $x\in \left \{ 0,1,2,3,4,..........,100 \right \}$, the $n$ ranges $\left \{ n:0\leq n\leq 111 \right \}$.

  • Taking $x= 0$ 
#include <stdio.h>
int mc91(int );
int main(void)
{
	int i = mc91(0); 
	printf("%d",i);
	return 0;
}

int mc91(int n)
{
    printf("%d\n",n);
    if (n > 100) 
    {
        return (n-10);
    }
    else 
    {
        return (mc91(mc91(n+11)));
    }
}

Output :

0        // Minimum Value printed for the given range of $x$
11
22
33
44
55
66
77
88
99
110
100
111     // Maximum Value printed for the given range of $x$
101
91
102
92
103
93
104
94
105
95
106
96
107
97
108
98
109
99
110
100
111
101      // Maximum value returned for the given range of $x$
............................................................

........................................................

.......................................................


  • Taking $x= 100$ 
#include <stdio.h>
int mc91(int );

int main(void)
{
	int i = mc91(100);
	printf("%d",i);
	return 0;
}

int mc91(int n)
{
    printf("%d\n",n);
    if (n > 100) 
    {
        return (n-10);
    }
    else 
    {
        return (mc91(mc91(n+11)));
    }
}

Output : 

100
111       // Maximum Value printed for the given range of $x$
101       // Maximum value returned for the given range of $x$
91

answered by Veteran (50.4k points) 22 90 410
selected by
Answer:

Related questions



Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Top Users Oct 2017
  1. Arjun

    23210 Points

  2. Bikram

    17018 Points

  3. Habibkhan

    6652 Points

  4. srestha

    5864 Points

  5. Debashish Deka

    5430 Points

  6. jothee

    4908 Points

  7. Sachin Mittal 1

    4762 Points

  8. joshi_nitish

    4274 Points

  9. sushmita

    3954 Points

  10. Silpa

    3698 Points


Recent Badges

Regular Juhi Sehgal
Popular Question vineet.ildm
Nice Comment Arjun
100 Club vipul verma
Notable Question jothee
Popular Question jothee
Nice Question shivangi5
Regular rinks5
Notable Question shipra tressa
Regular sasi
27,247 questions
35,056 answers
83,703 comments
33,183 users