Simvik

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:

9

All negative

int v[] = { -5, -2, -9 };
printf("%d\n", largest(v, 3));

Expected output:

-2

Learn it first

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

More Arrays and text problems