[刷题C] 习题4-5 换硬币 (20分)
浙大版《C语言程序设计(第3版)》题目集
https://pintia.cn/problem-sets/12/problems/291
#include <stdio.h>
int main(void)
{
int x, y, z;
int n;
int count = 0;
scanf("%d", &n);
for(x = n / 5; x >0 ; x--)
{
for(y = (n - 5 * x) / 2 ; y > 0; y-- )
{
for(z = n - 5 * x - y * 2; z > 0 ; z--)
if (5 * x + 2 * y + z == n)
{
printf("fen5:%d, fen2:%d, fen1:%d, total:%d\n", x, y, z, x + y + z);
count++;
}
}
}
printf("count = %d\n", count);
return 0;
}
需要注意题目要求输出顺序从大到小。