Even Numbers in C

Level 3107 keystrokes

Filters and prints only even numbers from an array.

C code

// Numbers 1 to 6
1int arr[] = {1, 2, 3, 4, 5, 6};
// Check every element
2for (int i = 0; i < 6; i++) {
// The remainder after dividing by 2 is 0 only for even numbers
3 if (arr[i] % 2 == 0)
// Printed only for 2, 4 and 6
4 printf("%d ", arr[i]);
5}

Output

2 4 6
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.

  • ,× 6
  • ;× 4
  • =× 4
  • (× 3
  • )× 3
  • [× 3
  • ]× 3
  • "× 2
  • {× 2
  • }× 2

More C examples at level 3

← C typing practice