Reverse Array in C

Level 398 keystrokes

Prints array elements in reverse order using a decrementing loop.

C code

// The array itself is not changed; only the print order is reversed
1int arr[] = {1, 2, 3, 4, 5};
// Start at the last index, 4, and count down to 0 with i--
2for (int i = 4; i >= 0; i--) {
// Print 5, 4, 3, 2, 1
3 printf("%d ", arr[i]);
4}
// End the line after the last element
5printf("\n");

Output

5 4 3 2 1
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.

  • ,× 5
  • ;× 5
  • "× 4
  • (× 3
  • )× 3
  • =× 3
  • -× 2
  • [× 2
  • ]× 2
  • {× 2

More C examples at level 3

← C typing practice