Kodewick
Start learning →
Basic←→0 / 70

Half-price sale

#033BasicArraysLoops4 min

Everything at the toy shop is half price today! In the first loop, change each price in prices to half of what it was (they are all even, so they halve exactly); the second loop is already there and shows the new prices, one per line.

Should show
5
12
4
15
main.c
#include <stdio.h>

int main(void) {
    int prices[4] = {10, 24, 8, 30};
    for (int i = 0; i < 4; i++) {
        // your code here: set prices[i] to half of itself
    }
    for (int i = 0; i < 4; i++) {
        printf("%d\n", prices[i]);
    }
    return 0;
}
Ctrl + Enter runs too
Result

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