What will be the output of the following pseudocode for a = 9, b = 7?Integer funn(Integer a, Integer b) Integer c Set c = 2 b = b mod c a = a mod c return a + b End function funn()[Note- mod finds the remainder after the division of one number by another. For example, the expression "5 mod 2 leaves a quotient of 2 and a remainder of 1.]Question 87AnswerA.5B.2C.17D.-5
Question
What will be the output of the following pseudocode for a = 9, b = 7?Integer funn(Integer a, Integer b) Integer c Set c = 2 b = b mod c a = a mod c return a + b End function funn()[Note- mod finds the remainder after the division of one number by another. For example, the expression "5 mod 2 leaves a quotient of 2 and a remainder of 1.]Question 87AnswerA.5B.2C.17D.-5
Solution
The pseudocode is as follows:
Integer funn(Integer a, Integer b)
Integer c
Set c = 2
b = b mod c
a = a mod c
return a + b
End function funn()
Given a = 9 and b = 7, let's go through the function step by step:
- Set c = 2. Now, c = 2.
- Set b = b mod c. This means b = 7 mod 2. The modulus operation finds the remainder after division, so 7 divided by 2 is 3 remainder 1. Therefore, b = 1.
- Set a = a mod c. This means a = 9 mod 2. The modulus operation finds the remainder after division, so 9 divided by 2 is 4 remainder 1. Therefore, a = 1.
- Return a + b. This means return 1 + 1, which is 2.
So, the output of the pseudocode for a = 9, b = 7 is 2. Therefore, the answer is B.2.
Similar Questions
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 80AnswerA.40B.0C.30D.44
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 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 ( )
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 = 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
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.