Vas a la compra con money y compras siguiendo la lista en orden: si te llega para un artículo, lo compras (y te queda menos dinero); si no, lo saltas y miras el siguiente. Escribe items_bought(prices, n, money) para devolver cuántos artículos compraste.
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++) {
// tu código aquí: si te llega, resta el precio a money y suma 1 a bought
}
return bought;
}
Ejecutar prueba los ejemplos. Cuando salgan bien, Enviar.