C语言求教。一个小小的编程问题,在线等

用100元人民币兑换10元,5元和1元的纸币(每一种都要有)共50张,请用穷举法编程计算共有几种兑换方案,每种方案各兑换多少张纸币.

数据输出格式: x = , y = , z =

count =

输入输出样例:

Input Sample:

Output Sample:

x = 2, y = 8, z = 40

count = 1

用X、Y、Z作为三重循环,大致如下:(循环变量还可以优化)

定义x,y,z,count为整形。

for(x=1;x<50;x++)

for(y=1;y<50;y++)

for(z=1;z<50;z++)
{
int m=x*10+y*5+z;
int n=x+y+z;
if(m==100 && n==50)
{
输出X,Y,Z
count++;
}
}
输出count。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-03-30
#include<stdio.h>
main()
{
int x, y, z, count=0;
for (x=1;x<10;x++){
for (y=1;y<18;y++){
for (z=1;z<=85; z++){
if (10 * x + 5 * y + z == 100){
count++;
printf("x=%d, y=%d, z=%d\n", x, y ,z);
}
}
}
}
printf("count=%d\n",count);
}

第2个回答  2013-03-30
#include <stdio.h>

void main()
{
int x,y,z,count=0;
for (x=1;x<10;x++)
for(y=1;y<20;y++)
for(z=1;z<100;z++)
if((10*x+5*y+z==100)&&(x+y+z==50))
{printf("x=%d,y=%d,z=%d\n",x,y,z);
count++;
printf("count=%d",count);
}
}
相似回答