Files
class-notes/2207/天天乐学答案/C语言/C语言(四)/2.c
T
2025-03-06 19:56:07 +08:00

35 lines
942 B
C

/*-------------------------------------------------------
将一张100元钞票换成等值的10元,5元,2元和1元的小钞,每次换成40张小钞,要求每一种小钞都要有,编程求出所有可能的换法总数输出并输出各换法的组合。(注:使用for循环)
结果:
10元钞票有1张,5元钞票有5张,2元钞票有31张,1元钞票有3张
10元钞票有1张,5元钞票有6张,2元钞票有27张,1元钞票有6张
10元钞票有1张,5元钞票有7张,2元钞票有23张,1元钞票有9张
。
。
。
总共有34种换法
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,d,s;
s=0;
/**********Program**********/
for(a=1;a<10;a++){
for(b=1;b<20;b++){
for(c=1;c<50;c++){
for(d=1;d<100;d++){
if(a*10+b*5+c*2+d == 100 && a+b+c+d==40){
s++;
/********** End **********/
printf("10元钞票有%d张,5元钞票有%d张,2元钞票有%d张,1元钞票有%d张\n",a,b,c,d);
}
}
}
}
}
printf("\n总共有%d种换法\n",s);
}