#include <stdio.h>
void makeChange(int coins[], int numCoins, int amount) {
for (int i = 0; i < numCoins - 1; i++) {
for (int j = 0; j < numCoins - i - 1; j++) {
if (coins[j] < coins[j + 1]) {
int temp = coins[j];
coins[j] = coins[j + 1];
coins[j + 1] = temp;
}
}
}
int result[numCoins];
for (int i = 0; i < numCoins; i++) {
result[i] = 0;
}
for (int i = 0; i < numCoins; i++) {
while (coins[i] <= amount) {
result[i]++;
amount -= coins[i];
}
}
printf("找零方案:\n");
for (int i = 0; i < numCoins; i++) {
if (result[i] > 0) {
printf("%d元 x %d\n", coins[i], result[i]);
}
}
}
int main() {
int coins[] = {25, 10, 5, 1};
int numCoins = sizeof(coins) / sizeof(coins[0]);
int amount = 42;
makeChange(coins, numCoins, amount);
return 0;
}