c语言编写程序

用一百元买瓜果和花生,瓜果和花生单价由scanf()输入,要求输出有多少种买法。

#include <stdio.h>
main()
{
int a,b,i,j;
printf("input two prices:\n");
scanf("%d%d",&a,&b);
for(i=0;i<100;i++)
for(j=0;j<100;j++)
if(i*a+j*b==100)
printf("huasheng:%2d,guaguo:%2d\n",i,j);
}
//调试成功
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-09-04
x,y为用户输入价格,i,j为瓜果和花生的重量 count计算种类
#include "stdio.h"
main()
{
int x,y;
int i,j,cuont=0;
printf("input x,y:\n");
scanf("%24d,%4d",&x,&y);
for(i=0;i<x;i++)
for(j=0;j<y;j++)
{
if(x*i+y*j==100)
{
count++;
printf("count:%d x*%d+y*%d==100",count,i,j);
}
}
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网