158k views
2 votes
.Like a loop, a recursive method must have some way to control the number of times it repeats itself? (true, false)

User Annon
by
5.4k points

1 Answer

5 votes

Answer:

True.

Step-by-step explanation:

In a recursive method, method call itself.If there is no control statement then it will call itself for infinite time.To prevent this we need to create a base/ termination condition in the recursive method. So that when it meets the base/termination condition, method will stop calling itself.

Here is an example of controlled recursive method :

void dig(int n)

{

// base condition to stop calling itself

if(n==0)

return;

else

{

cout<<n%10<<" ";

// function will itself until it meets the base condition

// recursive call

rdig(n/10);

}

}

this method to print the digits of a number in revers order.first it will print the last digit and update the number as num/10. this will repeat until num become 0. When it reaches the base condition it will stop calling itself and returned.

User Amik
by
4.9k points