985 views

3 Answers

Best answer
2 votes
2 votes
int x=foo(1000,1500); // this line in main called foo

foo(1000,1500) $\rightarrow$ bar(1000,1500) $\rightarrow$ bar(500,1000) $\rightarrow$ bar(0,500)

now coming bakwards from the recursive stack

bar(0,500) returns n= 500 to bar(0,500)

bar(0,500) returns 500 to bar(500,1000)

bar(500,1000) returns 500 to bar (1000,1500)

bar(1000,1500) returns 500 to foo(1000,1500)

Now in foo

return(m*n/bar(m,n));

becomes

return(1000*1500/500); = return(1000,*3) = return 3000

so foo(1000,1500) returns 3000 to x in main()

printf("%d",x); // prints 3000.

$\therefore$ Output is 3000.

edited by
1 votes
1 votes

x=foo(1000,1500)

foo()=1500000/bar(1000,1500)

foo()=1500000/bar(500,1000)

foo()=1500000/bar(0,500)

foo()=1500000/500=3000  => x=3000

hence Answer is 3000

0 votes
0 votes
You need not check for such large values just take m=10 and n=15. You will find that the value returned by bar(m,n) is 5.

m*n here is equal to 150 when you divide 150 by 5 you get 30 . you just need to add 2 additional zeros (m=10*100 and n=15*100)to get the result i.e., 3000

Related questions

2 votes
2 votes
2 answers
2
srestha asked May 12, 2019
1,075 views
Consider the following function $foo()$void foo(int n){ if(n<=0) printf("Bye"); else{ printf("Hi"); foo(n-3); printf("Hi"); foo(n-1); } }Let $P(n)$ represent recurrence r...