Max of an array in C
Finds the largest element, and shows why the length has to travel with the array.
int max_array(const int *items, int n) {
int best = items[0];
for (int i = 1; i < n; i++) {
if (items[i] > best)
best = items[i];
}
return best;
}
Keywords and builtins used here
constforifintmax_arrayreturn
The run, in numbers
- Lines
- 8
- Characters to type
- 146
- Tokens
- 57
- Three-star pace
- 90 tpm
At the three-star pace of 90 tokens a minute, this run takes about 38 seconds.
Step 2 of 5 in Arrays & strings, step 23 of 35 in Language basics.