/*编程序,输入正整数m,它代表一个人民币钱数(元数)。求取这样一个方案,使用最少张数的人民币纸币,凑成上述的钱数m,并输出求取结果。
注意,现在共有7种元以上面值的人民币纸币,分别为:100,50,20,10,5,2,1。*/
# include <stdio.h>
//100,50,20,10,5,2,1。
void main()
{
int m,hundred=0,fifty=0,twenty=0,ten=0,five=0,two=0,one=0;
int result;
system("graftabl 936");
printf("input money:");
scanf("%d",&m);
result=m;
while(m)
{
while(m>=100)
{
hundred++;
m=m-100;
}
while(m>=50)
{
fifty++;
m=m-50;
}
while(m>=20)
{
twenty++;
m=m-20;
}
while(m>=10)
{
ten++;
m=m-10;
}
while(m>=5)
{
five++;
m=m-5;
}
while(m>=2)
{
two++;
m=m-2;
}
while(m>=1)
{
one++;
m=m-1;
}
}
printf("%d=\n%d张一百的\n%d张五十的\n%d张二十的\n%d张十快的\n%d张五快的\n%d张2块的\n%d张一块的",result,hundred,fifty,twenty,ten,five,two,one);
getch();
}
还可发 把上面的内循环中的while 改成else if