retagged by
307 views
2 votes
2 votes

Read the below code snippet:
 

 int  joo( int num )
{
int result = 0 ;
if ( num <= 1)
return 1;
else
{
for ( i=num; i >= 1; i - - )
{
result  + = joo( i / 3) ;
}
}
return result;
}

When $num = 6$, the return value of the function is _____.

retagged by

1 Answer

Best answer
3 votes
3 votes
for i=6

result=result+joo(2)

                     |

                  result+joo[0]=0+1=1

                  result+joo[0]=1+1=2(for loop executes  twice for joo(2))

  

i=5

result=2+joo(1)=2+1=3;

i=4

result=3+joo(1)=4

i=3

result=4+joo(1)=5

i=2

result=5+joo(0)=6

i=1

result=6+joo(0)=7

ans:7
selected by
Answer:

Related questions

0 votes
0 votes
1 answer
1
Bikram asked Feb 9, 2017
343 views
The following function finds the $GCD$ recursively. int GCD(int k, int u) { if( u = = 0 ) return k ; else return GCD( u , ____); }Fill in the blank with the most appropri...
2 votes
2 votes
1 answer
2
3 votes
3 votes
3 answers
3
Bikram asked Feb 9, 2017
720 views
A radio is available at $\text{₹} 27780/-$ cash price, or three equal annual installments at $15\%$ per annum under $CI$ compounding annually. Each installment amount, ...