如何c++编程解决用最少的张数人民币凑成所需钱数?

Diamond me 2024-05-24 06:12:18
最佳回答
//有浓重的c风格,习惯,不好意思// zd_60.cpp : defines the entry point for the console application.//#include <string.h>#include <stdio.h>#include <conio.h>class money{private: int total; int result[7];public: money(int total); void num(); int *getresult();};money::money(int a){ total=a; for(int i=0;i<7;i++) result[i]=0;}void money::num(){ if(total>=100) { total-=100; result[0]++; th**->num(); } else if(total>=50) { total-=50; result[1]++; th**->num(); } else if(total>=20) { total-=20; result[2]++; th**->num(); } else if(total>=10) { total-=10; result[3]++; th**->num(); } else if(total>=5) { total-=5; result[4]++; th**->num(); } else if(total>=2) { total-=2; result[5]++; th**->num(); } else if(total>=1) { total-=1; result[6]++; th**->num(); } else return;}int* money::getresult(){ return result;}int main(int argc, char* argv[]){ int rmb; printf("输入钱数:\n"); scanf("%d",&rmb); money a=money(rmb); a.num(); int *result=a.getresult(); printf("需要的张数为:\n100\t 50\t 20\t 10\t 5\t 2\t 1\t\n"); for(int i=0;i<7;i++) printf("%3d\t",result[i]); getch(); return 0;}输入钱数:8759需要的张数为:100 50 20 10 5 2 1 87 1 0 0 1 2 0 20210311
汇率兑换计算器

类似问答
汇率兑换计算器

热门推荐
热门问答
最新问答
推荐问答
新手帮助
常见问题
房贷计算器-九子财经 | 备案号: 桂ICP备19010581号-1 商务联系 企鹅:2790-680461

特别声明:本网为公益网站,人人都可发布,所有内容为会员自行上传发布",本站不承担任何法律责任,如内容有该作者著作权或违规内容,请联系我们清空删除。