For Loop Even Numbers in C

Level 254 keystrokes

Uses a for loop that starts at 2 and adds 2 each time, printing the even numbers up to 10: "2 4 6 8 10".

C code

// i starts at 2 and i += 2 skips the odd numbers; the loop runs while i <= 10
1for (int i = 2; i <= 10; i += 2) {
// Prints 2, 4, 6, 8 and 10, each followed by a space
2 printf("%d ", i);
3}

Output

2 4 6 8 10
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this C code and how often they appear.

  • ;× 3
  • =× 3
  • "× 2
  • (× 2
  • )× 2
  • ,× 1
  • {× 1
  • }× 1
  • %× 1
  • +× 1

More C examples at level 2

← C typing practice