Largest element
Track the best value seen so far. An easy embedded C problem (Arrays and text), run and graded in the browser.
easy · Arrays and text · arrays · max
Return the largest of the first n elements of values. n is at least 1.
Starter code
int largest(const int values[], int n) {
return 0;
}Example tests
Mixed values
int v[] = { 3, 9, 2 };
printf("%d\n", largest(v, 3));Expected output:
9All negative
int v[] = { -5, -2, -9 };
printf("%d\n", largest(v, 3));Expected output:
-2Learn 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.
- Count readings above a threshold · Count the elements that pass a test.
- 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.