You go shopping with money, buying down the list in order: if you can afford an item you buy it (and have less money left); if not, you skip it and look at the next. Write items_bought(prices, n, money) to return how many items you got.
items_bought({5, 12, 3, 8}, 4, 20)→3items_bought({}, 0, 10)→0int items_bought(int prices[], int n, int money)int items_bought(int prices[], int n, int money) {
int bought = 0;
for (int i = 0; i < n; i++) {
// your code here: if you can afford it, take the price off money and add 1 to bought
}
return bought;
}
Run tries the examples. When they look right, Submit.