Kodewick
Start learning →
Basic←→0 / 70

Share the candy

#053BasicPointersFunctions4 min

17 candies shared by 5 kids, everyone the same, the rest kept aside. A function can return only one value, so share hands back both through pointers: each kid's share into *each, the leftovers into *left.

Should show
Each: 3, left: 2
main.c
#include <stdio.h>

void share(int candies, int kids, int *each, int *left) {
    // your code here: *each is candies divided by kids, *left is the remainder
}

int main(void) {
    int each = 0, left = 0;
    share(17, 5, &each, &left);
    printf("Each: %d, left: %d\n", each, left);
    return 0;
}
Ctrl + Enter runs too
Result

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