Array Minimum in C

Level 3117 keystrokes

Finds the minimum value in an integer array using a loop.

C code

// The values to search
1int a[] = {8, 3, 9, 1, 5};
// The first element is the minimum so far
2int min = a[0];
// Without braces, the loop body is only the next statement (the if)
3for (int i = 1; i < 5; i++)
// Keep the smaller value: 8 → 3 → 1
4 if (a[i] < min) min = a[i];
// Runs once after the loop and prints 1
5printf("%d", min);

Output

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.

  • ;× 6
  • ,× 5
  • [× 4
  • ]× 4
  • =× 4
  • (× 3
  • )× 3
  • "× 2
  • +× 2
  • <× 2

More C examples at level 3

← C typing practice