把一元鈔票換成一分二分五分硬幣每種至少一枚?
先假設已經每種有10枚了,這樣就成了求2毛錢可以換成幾枚的問題了;
程序:
#include<conio.h>
#include<stdio.h>
void main()
{
int one,two,five;
for(one=0;one<=20;one++)
for(two=0;two<=10;two++)
for(five=0;five<=4;five++)
if(one+2*two+5*five==20)
printf("one:%-2d--two:%-2d--five:%-2d\n",one+10,two+10,five+10);
getch();
}