Kodewick
Start learning →
Mini challenge←→0 / 70

Lemonade stand

#054Mini challengePointersArrays6 min

The lemonade stand wrote down the cups sold on each of 7 days. low_high finds both the fewest and the most at once and hands them back through the pointers low and high. Both start at the first day; add the comparisons in the loop.

Should show
Lowest: 8, highest: 21
main.c
#include <stdio.h>

void low_high(int cups[], int n, int *low, int *high) {
    *low = cups[0];
    *high = cups[0];
    for (int i = 1; i < n; i++) {
        // your code here: if smaller than *low replace *low; if bigger than *high replace *high
    }
}

int main(void) {
    int cups[] = {12, 8, 21, 15, 9, 18, 14};
    int low, high;
    low_high(cups, 7, &low, &high);
    printf("Lowest: %d, highest: %d\n", low, high);
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.