Kodewick
Start learning →
Mini challenge←→0 / 70

Top up the bowl

#055Mini challengePointersArrays6 min

Four cats' bowls each have some grams of food left. Make the pointer least point at the bowl with the least, then add 50 g to that bowl through it. Every bowl gets printed at the end.

Should show
40
65
30
25
main.c
#include <stdio.h>

int main(void) {
    int bowls[] = {40, 15, 30, 25};
    int *least = &bowls[0];
    for (int i = 1; i < 4; i++) {
        // your code here: if this bowl has less, point least at it
    }
    // your code here: add 50 through least
    for (int i = 0; i < 4; i++) {
        printf("%d\n", bowls[i]);
    }
    return 0;
}
Ctrl + Enter runs too
Result

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