Simvik

Count readings above a threshold

Count the elements that pass a test. An easy embedded C problem (Arrays and text), run and graded in the browser.

easy · Arrays and text · arrays · counting

Return how many of the first n elements of values are greater than threshold. A value equal to the threshold does not count.

Starter code

int count_above(const int values[], int n, int threshold) {
  return 0;
}

Example tests

Two readings above

int v[] = { 1, 5, 8, 3 };
printf("%d\n", count_above(v, 4, 3));

Expected output:

2

None above

int v[] = { 1, 5, 8, 3 };
printf("%d\n", count_above(v, 4, 10));

Expected output:

0

Learn it first

  • Arrays and text · Many values under one name, looping over them safely, and strings.

More Arrays and text problems