在某国使用1角、2角、5角的硬币可以组成1元钱。编程输出有多少种组成方法。
#include<iostream>
#include<iomanip>
//setw(n)可以设置字符以特定宽度输出,它必须包含iomanip这个头文件。
using namespace std;
int main() {
int count = 0;
for (int a=0;a<=10;a++)
for (int b = 0; b <= 5; b++)
for (int c = 0; c <= 2; c++)
if (a + b * 2 + c * 5 == 10) {
count++;
cout <<setw(4)<< count<<setw(4)<< a<<setw(4) << b <<setw(4) << c<<endl;
}
return 0;
}