Question:

Consider the following code blocks. 

A. for (i=0; i<1000; i++) 
\(\hspace{1cm}\) statement block; 
B. for (i=0; i<100; i+=2) 
\(\hspace{1cm}\) statement block; 
C. for (i=1; i<1000; i*=2) 
\(\hspace{1cm}\) statement block; 
D. for (i=0; i<10; i++) 
\(\hspace{1cm}\) for (j=0; j<10; j++) 
\(\hspace{2cm}\) statement block; 
Arrange the number of iterations of the above loops (number of times 'statement block' is executed) in ascending order.

Show Hint

In loops, the number of iterations depends on the starting value, the condition, and the increment or update. For exponential increments (e.g., \(i*=2\)), the number of iterations will be much smaller.
Updated On: Sep 25, 2025
  • A, B, C, D
  • A, B, C, D
  • B, A, D, C
  • C, B, D, A
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is C

Solution and Explanation

Step 1: Evaluate each loop's number of iterations. 
- **A:** The loop runs from \(i=0\) to \(i<1000\) with an increment of 1. Therefore, it runs 1000 times. 

- **B:** The loop runs from \(i=0\) to \(i<100\) with an increment of 2. Therefore, it runs 50 times. 

- **C:** The loop runs from \(i=1\) to \(i<1000\) with an increment where \(i\) is multiplied by 2 each time. Therefore, the loop runs approximately 10 times (\(i = 1, 2, 4, 8, \dots\)). 

- **D:** This is a nested loop. The outer loop runs 10 times, and for each iteration of the outer loop, the inner loop runs 10 times. Therefore, the loop runs \(10 \times 10 = 100\) times.

Step 2: Arrange the number of iterations in ascending order. 
- **B** has 50 iterations. 

- **D** has 100 iterations. 

- **A** has 1000 iterations. 

- **C** has approximately 10 iterations. 

Thus, the correct order of iterations is **B, A, D, C**, which corresponds to option (3).

Was this answer helpful?
0
0

Questions Asked in CUET PG exam

View More Questions