What will be the output of the following pseudocode for p = 6, q = 27Integer funn ( integer p, integer q )if ( p> 0 )return p + q + funn ( p - 3, q ) + funn (p-8, q-2 )end if return q - 2end function funn ( )
Question
What will be the output of the following pseudocode for p = 6, q = 27Integer funn ( integer p, integer q )if ( p> 0 )return p + q + funn ( p - 3, q ) + funn (p-8, q-2 )end if return q - 2end function funn ( )
Solution
The pseudocode provided is a recursive function. Here's how it works:
- The function
funnis called withp = 6andq = 27. - Since
p > 0, it enters the if condition and calls the functionfunntwice, once withp - 3andqand once withp - 8andq - 2. - The first recursive call is
funn(3, 27). Againp > 0, so it callsfunn(0, 27)andfunn(-5, 25). funn(0, 27)returns27 - 2 = 25becausep = 0is not greater than 0.funn(-5, 25)returns25 - 2 = 23becausep = -5is not greater than 0.- So,
funn(3, 27)returns3 + 27 + 25 + 23 = 78. - The second recursive call is
funn(-2, 25). It returns25 - 2 = 23becausep = -2is not greater than 0. - So,
funn(6, 27)returns6 + 27 + 78 + 23 = 134.
Therefore, the output of the pseudocode for p = 6 and q = 27 is 134.
Similar Questions
What will be the output of the following pseudocode for a = 4, b = 6?Integer funn(Integer a, Integer b) If(a > 1) Return a * funn (b - 6, a - 4) Else Return 1 End If Return a + b End function funn()Question 79AnswerA.7B.17C.4D.0
What will be the output of the following pseudocode for a = 2, b = 6?Integer funn(Integer a, Integer b If(a > 0) If(b > 0) Return a + b + funn(a + 1, 0) + funn(a + 2, 0) + funn(a + 3, 0) End If End If Return a + bEnd Function funn()
What will be the output of the following pseudocode?Integer p, q, rset p= 1, q= 1, r= 2q = p - 1q = r - 1if (p + 2 > q -6)if (q+2 > p- 6)p = 2end ifq= 2if (r> 5)p = qend ifend ifprintf p + q + r
What will be the output of the following pseudocode for a = 10, b = 11?Integer funn(Integer a, Integer b)if(0)return a - b - funn(-7, -1)End ifa = a + a + a + areturn aEnd function funn()Question 82AnswerA.30B.44C.0D.40
What will be the output of the pseudocode for p=3, q=1?Integer funn( integer p, integer q)if(q&1>0 AND p&3>0)return p^qelse return funn (p,q)end if end function funn( )[Note- &:bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit of the second operand. The corresponding result bit is set to 1. Otherwise , the corresponding result bit is set to 0.^ is the bitwise exclusive OR operator that compares each bit of its first operand to the corresponding bit of its second operand. If one is 1 , the corresponding result bit is set to 1. Otherwise, the corresponding result it is set to 0].
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.