Bird
0
0

You want to print all even numbers from 2 to 10 using a loop in C. Which loop is best and why?

hard📝 Application Q15 of 15
C - Loops
You want to print all even numbers from 2 to 10 using a loop in C. Which loop is best and why?
AUse nested loops to check each number from 2 to 10
BUse a while loop starting at 1, increment by 1 until 10 and print if even
CUse a do-while loop starting at 10, decrement by 2 until 2
DUse a for loop starting at 2, increment by 2 until 10
Step-by-Step Solution
Solution:
  1. Step 1: Understand the task

    We need to print even numbers from 2 to 10, which are 2,4,6,8,10.
  2. Step 2: Evaluate loop options

    Use a for loop starting at 2, increment by 2 until 10 uses a for loop starting at 2 and increments by 2, directly printing even numbers efficiently.
  3. Final Answer:

    Use a for loop starting at 2, increment by 2 until 10 -> Option D
  4. Quick Check:

    For loop with step 2 prints evens directly [OK]
Quick Trick: Increment by 2 in for loop to print evens directly [OK]
Common Mistakes:
  • Using nested loops unnecessarily
  • Starting from 1 and checking each number
  • Using do-while with wrong direction

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes