A = 0, B = 9….. Perform until a > b Add 2 to a End-perform How many additions are performed?
-
3
-
4
-
5
-
6
The loop starts with a=0, b=9 and adds 2 to a each iteration until a > b. Iterations: a=0→2→4→6→8→10. When a=10, the condition 10 > 9 is true and the loop exits. The addition operation executes exactly 5 times.
To determine how many additions are performed until a > b, let's go through each step:
Step 1: A = 0, B = 9 (Initial values) Step 2: Add 2 to A (A = A + 2) -> A = 2 Step 3: Check if A > B (2 > 9) -> False Step 4: Add 2 to A (A = A + 2) -> A = 4 Step 5: Check if A > B (4 > 9) -> False Step 6: Add 2 to A (A = A + 2) -> A = 6 Step 7: Check if A > B (6 > 9) -> False Step 8: Add 2 to A (A = A + 2) -> A = 8 Step 9: Check if A > B (8 > 9) -> False Step 10: Add 2 to A (A = A + 2) -> A = 10 Step 11: Check if A > B (10 > 9) -> True
The condition a > b is satisfied after 5 additions (Step 2 to Step 11). Therefore, the correct answer is C) 5.