#include<stdio.h>
int main()
{
int price[4];
int i,num1,num2,num3,num0,temp=0,sum;
printf("\n请输入总金额:");
scanf("%d",&sum);
printf("\n请输入四种物品的单价:");
for(i=0;i<4;i++)
scanf("%d",&price[i]);
for(num0=0;num0<=sum/price[0];num0++)
for(num1=0;num1<=sum/price[1];num1++)
for(num2=0;num2<=sum/price[2];num2++)
for(num3=0;num3<=sum/price[3];num3++)
{
temp=num0*price[0]+num1*price[1]+num2*price[2]+num3*price[3];
if((temp==sum) && (num0||num1)&& (num0||num2)&& (num0||num3)&& (num1||num2)&& (num1||num3)&& (num2||num3))
printf("{\t物品数量为%d,%d,%d,%d\t}\n",num0,num1,num2,num3);
}
return 0;
}
[
本帖最后由 comewest 于 2014-12-11 12:11 编辑 ]