-
Notifications
You must be signed in to change notification settings - Fork 430
/
换分币问题.c
34 lines (31 loc) · 1.58 KB
/
换分币问题.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//将5元的人民币兑换成1元、5角和1角的硬币,共有多少种不同的兑换方法。
#include<stdio.h>
int main()
{
int x, y, z, count=1;
printf("可能的兑换方法如下:\n");
for( x=0; x<=50; x+=10 ) /*x为1元硬币钱数,其取值为0,10,20,30,40,50*/
for( y=0; y<=50-x; y+=5 ) /*y为5角硬币钱数,其取值为0,5,10,15,20,25,30,35,40,,45,50*/
for( z=0; z<=50-x-y; z++) /*z为1角硬币钱数,其取值为0,1,...50*/
if(x+y+z==50)
{
/*输出时,每行最多三种情况*/
printf(count%3 ? "%d: 10*%d+5*%d+1*%d\t" : "%d:10*%d+5*%d+1*%d\n", count, x/10, y/5, z);
count++;
}
return 0;
}
//运行结果:
//可能的兑换方法如下:
//1: 10*0+5*0+1*50 2: 10*0+5*1+1*45 3:10*0+5*2+1*40
//4: 10*0+5*3+1*35 5: 10*0+5*4+1*30 6:10*0+5*5+1*25
//7: 10*0+5*6+1*20 8: 10*0+5*7+1*15 9:10*0+5*8+1*10
//10: 10*0+5*9+1*5 11: 10*0+5*10+1*0 12:10*1+5*0+1*40
//13: 10*1+5*1+1*35 14: 10*1+5*2+1*30 15:10*1+5*3+1*25
//16: 10*1+5*4+1*20 17: 10*1+5*5+1*15 18:10*1+5*6+1*10
//19: 10*1+5*7+1*5 20: 10*1+5*8+1*0 21:10*2+5*0+1*30
//22: 10*2+5*1+1*25 23: 10*2+5*2+1*20 24:10*2+5*3+1*15
//25: 10*2+5*4+1*10 26: 10*2+5*5+1*5 27:10*2+5*6+1*0
//28: 10*3+5*0+1*20 29: 10*3+5*1+1*15 30:10*3+5*2+1*10
//31: 10*3+5*3+1*5 32: 10*3+5*4+1*0 33:10*4+5*0+1*10
//34: 10*4+5*1+1*5 35: 10*4+5*2+1*0 36:10*5+5*0+1*0