Question:

Consider the following steps:
1. Put $x = 1$, $y = 2$
2. Replace $x$ by $xy$
3. Replace $y$ by $y + 1$
4. If $y = 5$ then go to step 6 otherwise go to step 5
5. Go to step 2
6. Stop
Then the final value of $x$ equals:

Show Hint

Always simulate small algorithm problems step-by-step; don’t try to shortcut unless you clearly see the pattern.
Updated On: Aug 7, 2025
  • 1
  • 24
  • 120
  • 720
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is B

Solution and Explanation

We trace the algorithm step by step:
Initially: $x = 1$, $y = 2$.
Step 2: $x \leftarrow x y = 1 2 = 2$.
Step 3: $y \leftarrow y + 1 = 3$. $y \neq 5$, so go to step 5.
Step 5 → Step 2: $x \leftarrow x y = 2 3 = 6$.
Step 3: $y \leftarrow 4$. $y \neq 5$, go to step 5.
Step 2: $x \leftarrow x y = 6 4 = 24$.
Step 3: $y \leftarrow 5$. This time $y = 5$, so go to step 6 and stop.
Final $x$ value = 24.
This process essentially multiplies $x$ by $y$ starting from 2 and increases $y$ by 1 until $y$ reaches 5, but stops before multiplying by 5. Therefore, $x = 2 3 4 = 24$.
Was this answer helpful?
0
0