What will be the output of the following pseudocode for a = 5, b = 1?Integer funn(Integer a, Integer b)if(b + a || a - b) && (b > a) && 1)a = a+b+b-2return 3-aElseEnd ifreturn a-b+1return a+b End function fun()Question 77AnswerA.11B.5C.16D.0
Question
What will be the output of the following pseudocode for a = 5, b = 1?Integer funn(Integer a, Integer b)if(b + a || a - b) && (b > a) && 1)a = a+b+b-2return 3-aElseEnd ifreturn a-b+1return a+b End function fun()Question 77AnswerA.11B.5C.16D.0
Solution
The pseudocode provided can be broken down as follows:
-
The function
funntakes two integersaandbas input. In this case,a = 5andb = 1. -
The first condition in the
ifstatement checks ifb + aora - bis true. Sinceb + a = 6anda - b = 4, both are non-zero and hence, in boolean context, they are true. The||operator means "or", so if either of the conditions is true, the whole condition is true. In this case, the condition is true. -
The second condition in the
ifstatement checks ifb > a. In this case,1 > 5is false. -
The
&&operator means "and", so for the wholeifcondition to be true, both the first and second conditions must be true. But the second condition is false, so the wholeifcondition is false. -
Since the
ifcondition is false, the code inside theifblock is not executed, and we move to theelseblock. -
However, there is no
elseblock in this pseudocode, so we move to the next line after theifblock. -
The next line is
return a-b+1, so the function returns5 - 1 + 1 = 5.
So, the output of the pseudocode for a = 5 and b = 1 is 5. Therefore, the answer is B.5.
Similar Questions
What will be the output of the following pseudocode for a = 5, b = 1?Integer funn(Integer a, Integer b)if((b mod a && a mod b) || (a ^ b > a))a=a^bElseEnd ifreturn a-breturn a+bEnd function funn()
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 pseudo code a=2, b=1?1. 2. Integer funn (Interger a, Integer b)3. if(4>b && b<a && b<a)4. a=b+25. a=b+26. b=a+17. return b – funn(b, b)8. End if9. b=1+b+a10. return b-a +1
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 following pseudocode for a = 4 and b = 9?Integer funn(Integer a, Integer b)If(a Return 1 + funn(a, b – 2)End IfIf(a^b >a &b)Return a ^ bElseReturn a &bEnd IfReturn 1End function funn()10-81424
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.