题目描述
653.钞票
C++ 代码
#include<iostream>
using namespace std;
int main()
{
//a:100, b:50, c:20, d:10, e:5, f:2, g:1
int x, temp; //用于暂存
int a, b, c, d, e, f, g, h; //存储每种面值的钞票的需求数量
cin >> x;
temp = x;
int N = x;
/*1. 对输入数值进行取余,得到除100 面额以外的钞票
2. 对输入数值进行除法运算,得到100的钞票数
3. 把temp赋给x,方便下次运算*/
temp = temp % 100; //76
a = x / 100; //5
x = temp; //76
//下面步骤同上
temp = temp % 50; //26
b = x / 50; //1
x = temp; //26
temp = temp % 20;
c = x / 20;
x = temp;
temp = temp % 10;
d = x / 10;
x = temp;
temp = temp % 5;
e = x / 5;
x = temp;
temp = temp % 2;
f = x / 2;
x = temp;
temp = temp % 1;
g = x / 1;
x = temp;
cout << N << endl;
cout << a << " nota(s) de R$ 100,00" << endl;
cout << b << " nota(s) de R$ 50,00" << endl;
cout << c << " nota(s) de R$ 20,00" << endl;
cout << d << " nota(s) de R$ 10,00" << endl;
cout << e << " nota(s) de R$ 5,00" << endl;
cout << f << " nota(s) de R$ 2,00" << endl;
cout << g << " nota(s) de R$ 1,00" << endl;
return 0;
}
CSDN:铜锣烧GZQ