This commit is contained in:
2026-06-15 09:00:38 +08:00
parent fec66377d5
commit 4640c5e02b
191 changed files with 6046 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#include <stdio.h>
int main() {
int money[] = {100, 50, 20, 10, 5, 1};
int n = 85;
printf("要找的钱数为:%d\n", n);
int num[6] = {0}; // 存储每种面值所需的数量
for (int i = 0; i < 6; i++) {
num[i] = n / money[i]; // 计算需要的面值数量
n = n % money[i]; // 更新剩余的钱数
}
for (int i = 0; i < 6; i++) {
printf("需要%d元面值%d枚\n", money[i], num[i]);
}
return 0;
}
Binary file not shown.
+21
View File
@@ -0,0 +1,21 @@
#include <stdio.h>
void makeGreedyChange(int m, int plan[][2], int size) {
for (int i = 0; i < size; i++) {
plan[i][1] += m / plan[i][0]; // 计算需要的面值数量
m = m % plan[i][0]; // 更新剩余的钱数
}
}
int main() {
int money = 90;
// 用一个二维数组 plan[6][2] 来存储每一种面值和其所对应的具体数目
int plan[6][2] = { {50, 0}, {20, 0}, {10, 0}, {5, 0}, {2, 0}, {1, 0} };
makeGreedyChange(money, plan, 6);
for (int i = 0; i < 6; i++) {
printf("%d元: %d张\n", plan[i][0], plan[i][1]);
}
return 0;
}
Binary file not shown.