某人想将手中的一张面值n元的人民币换成10元、5元、2元和1元面值的票子。有几种换法?若要求换正好40张,且每种票子至少一张。有几种换法?
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int main()
{
int i, x, y, z, n=0,m=0, a, b, c, d,total;//a是10元变量,b是5元变量,c是2元变量,d是1元变量,
while (scanf("%d", &i) != EOF)
{
x = i % 10, y = x % 5, z = y % 2;
a = i / 10, b = x / 5, c = y / 2, d = y;
while(a>0)//10位判断
{
while (b >0)
{
while (c > 0)
{
n = n + 1;
d = (i - (a * 10 + b * 5 + c * 2));
total = a + b + c + d;
if (total == 40 && d > 0)
{
m = m + 1;
}
c = c - 1;
}
b = b - 1;
c = (i-(a * 10 + b * 5)) / 2;
}
a = a - 1;
b = (i - a * 10) / 5;
c = (i - (a * 10 + b * 5)) / 2;
}
printf("总换法=%d\n合计40张换法=%d\n", n,m);
return 0;
}
return 0;
}