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:
2None above
int v[] = { 1, 5, 8, 3 };
printf("%d\n", count_above(v, 4, 10));Expected output:
0Learn it first
- Arrays and text · Many values under one name, looping over them safely, and strings.
More Arrays and text problems
- Sum an array · Visit every element with a loop.
- Largest element · Track the best value seen so far.
- Fill an array · Write to the elements of an array.
- Find a value · Search an array and report where a value is.
- Average of readings · Combine a loop with integer division.
- Length of a string · Find where a piece of text ends.
- Count a character · Loop over text and count matches.