人民币问题
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]);
}
}
编写一个函数计算金额"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]);
}
}
相关文章推荐
- 人民币找零 vs 硬币问题 贪心 vs 动态规划
- 半小时解决人民币升值的问题!清晰明了!
- “人民币找零”问题的贪婪法解决算法
- “人民币找零”问题的贪婪法解决算法
- 【贪心法】:人民币找钱问题
- 人民币问题
- 1073:人民币问题
- 人民币大小写转换问题
- 【NEUQ OJ】1202: 人民币问题
- “人民币找零”问题的贪婪法解决算法
- App Store开人民币付款先河 苹果中国本土化路上问题多
- “人民币找零”问题的贪婪法解决算法
- 人民币贬值和外汇储备的问题
- 人民币小写转化为大写转换(解决中间多个0的问题)
- 上车人数,人民币问题<C语言>
- 人民币问题
- 1073: 人民币问题
- 人民币处理问题(原创)
- PayPal美元和人民币之货币转换问题
- “人民币找零”问题的贪婪法解决算法