C++百钱问题:将100元人民币换成1,2,5元,共有几种换法

编程入门 行业动态 更新时间:2024-10-21 06:33:08

C++百钱问题:将100元人民币换成1,2,5元,共有<a href=https://www.elefans.com/category/jswz/34/1769370.html style=几种换法"/>

C++百钱问题:将100元人民币换成1,2,5元,共有几种换法

百钱问题:将100元人民币换成1,2,5元,共有几种换法

#include<iostream>
#include<stdlib.h>
using namespace std;
int main() {int count = 0;//换法int temp;int m = 100;//总钱数int a = 1;//1元面值int b = 2;//2元面值int c = 5;//5元面值//a, b, c的值还可以是10,20,50for (int i = 0; i <= m / b; ++i) {for (int j = 0; j <= m / c; ++j) {temp = m - (b * i + c * j);if (temp >= 0 && temp % a == 0) {//只要2元和5元的总和加起来不大于100,剩下的都换1元++count;}}}cout << "换法有" << count << "种\n";system("pause");return 0;
}

更多推荐

C++百钱问题:将100元人民币换成1,2,5元,共有几种换法

本文发布于:2024-03-08 15:46:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1721336.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几种   人民币

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!