2025-03-06 19:56:07 +08:00

35 lines
942 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
将一张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);
}