1 1 vote What does the following function compute in terms of $n$ and $d$, for integer values of $d$ ? Note that the operation $/$ denotes floating point division, even if the arguments are both integers. function foo(n,d){ if (d == 0){ return 1; }else{ if (d < 0){ return foo(n,d+1)/n; }else{ return n*foo(n,d-1); }}} $log_dn$ if $d < 0$ , $n^d\ $if$ \ d>0$. $n^d$ for all the values of $d$. $n \times d$ if $d>0$ ,$n\div d$ if $d<0$. $n \times d$ for all the values of $d$. Programming in C cmi2017 programming output + – Tesla! 1.4k views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
1 1 vote Let's take two cases: Case 1: $n=5, d=3$ $foo(5,3)$ $5*foo(5,2)$ $5*5*foo(5,1)$ $5*5*5*foo(5,0)$ $5*5*5*1= 5^3 = n^d$ Case 2: $n=5, d=-1$ $foo(5,-1)$ $foo(5,0)/5$ $\frac{1}{5}= 5^{-1}= n^d$ In both the case option B) satisfies Ashwani Kumar 2 answered Sep 11, 2019 Ashwani Kumar 2 comment Share Follow 0 reply Please log in or register to add a comment.
1 1 vote Answer: soujanyareddy13 answered May 6, 2021 soujanyareddy13 comment Share Follow 0 reply Please log in or register to add a comment.
0 0 votes IF you observer the logic then you will find that when ever the valve of d is greater than zero the valve n is multiplied to itself and d is decremented, and this will be done till the value of d!=0. Similarly if d is negative then valve of n is divided by itself and d is incremented by 1 and this continue till d!=0. So, Ans C Tarun kushwaha 1 answered Feb 5, 2018 • reshown Sep 2, 2018 by Tarun kushwaha 1 Tarun kushwaha 1 comment Share Follow See all 3 Comments 3 3 Comments reply Tesla! commented Feb 5, 2018 reply Follow flag No official answer is different 0 0 replyShare Anmol Verma commented Aug 19, 2018 reply Follow flag Is the ans B..... 1 1 replyShare Tesla! commented Aug 19, 2018 reply Follow flag Yes B is answer 0 0 replyShare Please log in or register to add a comment.