您的位置:首页 > 其它

人民币问题

2006-11-30 15:58 211 查看
人民币问题
编写一个函数计算金额"X"需要多少张面值为n元的纸币。在主函数中输入一个金额值,调用该函数,计算组成该金额最少需要多少张纸币。
注:人民币面值不包括角和分 有1元、2元,5元,10元、20元、50元、100元。

#include <stdio.h>
void main()
{
int i, j, k,tmp=0,total=0;
int money[7] = {100,50,20,10,5,2,1};
int howEnt[7];

scanf("%d",&j);
for (i = 0; i < 7; i++)
{
howEnt[i] = (j-tmp) / money[i]; //求每个面值的个数
tmp += howEnt[i]*money[i];
}
for(k = 0;k < 7; k++)
{
total+=howEnt[k];
}
printf("The min number of cards is %d/n",total);
printf("see the numbers under the statement!/n");

for (k = 0; k < 7; k++)
{
printf("The %d card is %d/n",money[k],howEnt[k]);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: