69,373
社区成员
![](https://csdnimg.cn/release/cmsfe/public/img/topic.427195d5.png)
![](https://csdnimg.cn/release/cmsfe/public/img/me.40a70ab0.png)
![](https://csdnimg.cn/release/cmsfe/public/img/task.87b52881.png)
![](https://csdnimg.cn/release/cmsfe/public/img/share-circle.3e0b7822.png)
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int one, two, five;
int count = 0;
for (five = 1; five <= 19; five++)
for (two = 1; two <= 47; two++) {
one = 100 - 5 * five - 2 * two;
if (one > 0) {
count++;
printf("第 %d 种换法:five = %d, two = %d, one = %d \n", count, five, two, one);
}
}
printf("一共有 %d 种换法", count);
return 0;
}
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i, j, k, m, n, r;
int a, b, c, d, e, f;
int count = 0;
for(r = 0; r <= 2; r++)
{
for(n = 0; n <= 5; n++)
{
for(m = 0; m <= 10; m++)
{
for(k = 0; k <= 20; k++)
{
for(j = 0; j <= 50; j++)
{
for(i = 0; i <= 100; i++)
{
int total = i * 1 + j * 2 + k * 5 + m * 10 + n * 20 + r * 50;
if(20 == total)
{
//printf("50:%d 20:%d 10:%d 5:%d 2:%d 1:%d\n", r, n, m, k, j, i);
for(a = 0; a < r; a++)
{
printf("50 ");
}
for(b = 0; b < n; b++)
{
printf("20 ");
}
for(c = 0; c < m; c++)
{
printf("10 ");
}
for(d = 0; d < k; d++)
{
printf("5 ");
}
for(e = 0; e < j; e++)
{
printf("2 ");
}
for(f = 0; f < i; f++)
{
printf("1 ");
}
printf("\n");
count++;
}
}
}
}
}
}
}
printf("\n\ncount = %d\n", count);
system("pause");
return 0;
}
运行结果:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 1 1 1 1 1 1 1 1 1 1
2 2 2 2 2 2 1 1 1 1 1 1 1 1
2 2 2 2 2 2 2 1 1 1 1 1 1
2 2 2 2 2 2 2 2 1 1 1 1
2 2 2 2 2 2 2 2 2 1 1
2 2 2 2 2 2 2 2 2 2
5 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
5 2 1 1 1 1 1 1 1 1 1 1 1 1 1
5 2 2 1 1 1 1 1 1 1 1 1 1 1
5 2 2 2 1 1 1 1 1 1 1 1 1
5 2 2 2 2 1 1 1 1 1 1 1
5 2 2 2 2 2 1 1 1 1 1
5 2 2 2 2 2 2 1 1 1
5 2 2 2 2 2 2 2 1
5 5 1 1 1 1 1 1 1 1 1 1
5 5 2 1 1 1 1 1 1 1 1
5 5 2 2 1 1 1 1 1 1
5 5 2 2 2 1 1 1 1
5 5 2 2 2 2 1 1
5 5 2 2 2 2 2
5 5 5 1 1 1 1 1
5 5 5 2 1 1 1
5 5 5 2 2 1
5 5 5 5
10 1 1 1 1 1 1 1 1 1 1
10 2 1 1 1 1 1 1 1 1
10 2 2 1 1 1 1 1 1
10 2 2 2 1 1 1 1
10 2 2 2 2 1 1
10 2 2 2 2 2
10 5 1 1 1 1 1
10 5 2 1 1 1
10 5 2 2 1
10 5 5
10 10
20
其二:
零钱限制为(1,2,5,10,20,50 元),100 元人民币有多少种换零方式?
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
int i, j, k, m, n, r;
int count = 0;
for(r = 0; r <= 2; r++)
{
for(n = 0; n <= 5; n++)
{
for(m = 0; m <= 10; m++)
{
for(k = 0; k <= 20; k++)
{
for(j = 0; j <= 50; j++)
{
for(i = 0; i <= 100; i++)
{
if(100 == i * 1 + j * 2 + k * 5 + m * 10 + n * 20 + r * 50)
{
count++;
}
}
}
}
}
}
}
printf("count = %dn", count);
system("pause");
return 0;
}
结果:
count = 4562system("mode con:cols=100 lines=500");
即可
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream ofs("yuan.txt", ios::out);
int one, two, five;
int leave = 0;
int maxtwo;
int count = 0;
char buffer[100];
for (five = 1; five <= 19; five++)
{
leave = 100 - five * 5;
maxtwo = (leave - 1) / 2;
for (two = 1; two <= maxtwo; two++)
{
one = leave - two - two;
count++;
sprintf_s(buffer, 100, "%5d: 5-%d, 2-%d, 1-%d\n", count, five, two, one);
printf_s("%s", buffer);
ofs.write(buffer, (streamsize)strlen(buffer));
if (five < 1 || two < 1 || one < 1)
{
system("pause");
}
}
}
sprintf_s(buffer, 100, "Count=%d\n", count);
printf_s("%s", buffer);
ofs.write(buffer, (streamsize)strlen(buffer));
ofs.close();
system("pause");
return 0;
}