Knowee
Questions
Features
Study Tools

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 ( )

🧐 Not the exact question you are looking for?Go ask a question

Solution

The pseudocode provided is a recursive function. Here's how it works:

  1. The function funn is called with p = 6 and q = 27.
  2. Since p > 0, it enters the if condition and calls the function funn twice, once with p - 3 and q and once with p - 8 and q - 2.
  3. The first recursive call is funn(3, 27). Again p > 0, so it calls funn(0, 27) and funn(-5, 25).
  4. funn(0, 27) returns 27 - 2 = 25 because p = 0 is not greater than 0.
  5. funn(-5, 25) returns 25 - 2 = 23 because p = -5 is not greater than 0.
  6. So, funn(3, 27) returns 3 + 27 + 25 + 23 = 78.
  7. The second recursive call is funn(-2, 25). It returns 25 - 2 = 23 because p = -2 is not greater than 0.
  8. So, funn(6, 27) returns 6 + 27 + 78 + 23 = 134.

Therefore, the output of the pseudocode for p = 6 and q = 27 is 134.

This problem has been solved

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].

1/3

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.