What will be the output of the following pseudo code ?1.Integer p,q,r2. Set p=6, q=6, r=43.if(r<p || (p-r)< (q+p))4. p=(p+9)+p5. if((4^q^9)<(9^4))6. p=2+r 7. End if8. p=(p+9)+q9. End if10. Print p+q+r
Question
What will be the output of the following pseudo code ?1.Integer p,q,r2. Set p=6, q=6, r=43.if(r<p || (p-r)< (q+p))4. p=(p+9)+p5. if((4^q^9)<(9^4))6. p=2+r 7. End if8. p=(p+9)+q9. End if10. Print p+q+r
Solution
Let's break down the pseudo code:
- Integer p,q,r
- Set p=6, q=6, r=4
- if(r<p || (p-r)< (q+p))
Here, r is less than p (4<6) and (p-r) is less than (q+p) (2<16), so the condition is true. Therefore, we enter the if block.
- p=(p+9)+p
Here, p is updated to (6+9)+6 = 21.
- if((4^q^9)<(9^4))
This is a bit tricky because the "^" operator could mean either "to the power of" or "bitwise XOR" depending on the language. However, in most languages, "^" is the bitwise XOR operator. So, 4 XOR 6 XOR 9 = 11, and 9 XOR 4 = 13. Since 11 is not less than 13, this condition is false, so we skip this if block.
-
p=2+r (This line is skipped because the condition in step 5 is false)
-
End if (End of the inner if block)
-
p=(p+9)+q
Here, p is updated to (21+9)+6 = 36.
-
End if (End of the outer if block)
-
Print p+q+r
Finally, we print the sum of p, q, and r, which is 36+6+4 = 46.
So, the output of the pseudo code will be 46.
Similar Questions
What will be the output of the following pseudocode?Integer p, q, r Set p = 0, q = 4, r = 3 If(p || r) If(p && r) p = p &r End If p = p ^ r End If Print p + q + rQuestion 90AnswerA.20B.10C.12D.7
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?1. int p=4, q=7, r=102. p=q mod r3. q=q+p4. r=r+q5. print p, q and r7 11 174 11 177 14 217 14 24
What will be the output of the following pseudocode?Integer p, q, rset p= 1, q= 4, r= 2if ( p&q)r =p&qend ifprint r- p - q[ Note- & bitwise AND - The bitwise AND operator ( & ) compares each bit of the first operand to the corresponding bit of the second operand if both bits are 1 the corresponding result bit is set to 1. otherwise, the corresponding result bit is set to 0]
What will be the output of the following pseudo code?1. Inteter a, b, c2. Set a=9, b=4, c=93. if ((b&a)<a)4. a=b&a5. End if6. Pring a+b+c
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.