Bird
0
0

You want to print all odd numbers from 1 to 9 using a for loop. Which code snippet correctly does this?

hard📝 Application Q8 of 15
C - Loops
You want to print all odd numbers from 1 to 9 using a for loop. Which code snippet correctly does this?
AAll of the above
Bfor(int i = 0; i <= 9; i++) { if(i % 2 == 1) printf("%d ", i); }
Cfor(int i = 1; i <= 9; i++) { if(i % 2 != 0) printf("%d ", i); }
Dfor(int i = 1; i < 10; i += 2) { printf("%d ", i); }
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each code snippet

    for(int i = 1; i < 10; i += 2) { printf("%d ", i); } increments by 2 starting at 1, printing odd numbers. for(int i = 0; i <= 9; i++) { if(i % 2 == 1) printf("%d ", i); } checks oddness inside loop. for(int i = 1; i <= 9; i++) { if(i % 2 != 0) printf("%d ", i); } also checks oddness with != 0.
  2. Step 2: Confirm all snippets print odd numbers 1 to 9

    All three approaches correctly print odd numbers from 1 to 9.
  3. Final Answer:

    All of the above -> Option A
  4. Quick Check:

    Multiple ways to print odd numbers [OK]
Quick Trick: Use increment by 2 or condition check for odds [OK]
Common Mistakes:
  • Using wrong increment step
  • Incorrect condition for odd numbers
  • Off-by-one errors in loop bounds

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes