钱兑换的加强版,求吧友一起探讨
题目:将10元钱兑换成1元,5角,1角的硬币,共40枚,计算有多少种兑换方法。并且求出最小枚数的组合,和最大枚数的组合。#include<stdio.h>
void main()
{
int x,y,z,j=0,a[5],min,max=0;
for(x=0;x<=10;x++)
for(y=0;y<=20;y++)
{z=40-x-y;
if(10*x+5*y+z==100)
{
j=j+1;
a[j]=x+y+z;
min=a[1];
printf("di %d zhong fangfa:1 yuan%dmei,5jiao%dmei,1jiao%dmei\n",j,x,y,z);
}
}
if(a[j]<min)
min=a[j];
if(a[j]>max)
max=a[j]
printf("gong you%d zhong ruihuan fanfang\n",j);
printf("zui xiao/da de zuhe fangfa si wei:%d,&d,x=%d,y=%d,z=%d",min,max,x,y,z);
}
#include<stdio.h>
void main()
{
int x,y,z,j=0,a[5],min;
for(x=0;x<=10;x++)
for(y=0;y<=20;y++)
{z=40-x-y;
if(10*x+5*y+z==100)
{
j=j+1;
a[j]=x+y+z;
min=a[1];
printf("di %d zhong fangfa:1 yuan%dmei,5jiao%dmei,1jiao%dmei\n",j,x,y,z);
}
}
if(a[j]<min)
min=a[j];
printf("gong you%d zhong ruihuan fanfang\n",j);
printf("zui xiao de zuhe fangfa si wei:%d,x=%d,y=%d,z=%d",min,x,y,z);
}
我这代码有错误,求指出.
[ 本帖最后由 叶舞秋风 于 2014-7-19 10:59 编辑 ]