习题4-5 换硬币 (20分)
程序员文章站
2022-06-07 18:18:27
...
习题4-5 换硬币 (20分)
代码:
#include <stdio.h>
int main()
{
int money = 0, i = 0, j = 0, count = 0;
scanf("%d", &money);
for (i = money / 5; i >= 1; i--)
{
for (j = (money - 5 * i) / 2; j >= 1; j--)
{
if ( money - 5 * i - 2 * j >= 1)
{
printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n", i, j, money - 5 * i - 2 * j, money - 4 * i - j);
count++;
}
}
}
printf("count = %d", count);
return 0;
}