用for循环去列出50,20,10,5的各有多少张,然后选择满足条件的就可以了
#include<stdio.h>
void main()
{
int a50,a20,a10,a5,M=500;
for(a50=1;a50<=(M-20-10-5)/50;a50++)
for(a20=1;a20<=(M-50-10-5)/20;a20++)
for(a10=1;a10<=(M-50-20-5)/10;a10++)
for(a5=1;a5<=(M-50-20-10)/5;a5++)
if(a50*50+a20*20+a10*10+a5*5==M&&a50+a20+a10+a5==30) printf("50的%d张 20的%d张 10的%d张 5的%d张\n",a50,a20,a10,a5);
system("pause");
}
[[it] 本帖最后由 faminxmu 于 2008-10-10 19:12 编辑 [/it]]