作業6-1 巧克力盒子包裝
阿新 • • 發佈:2017-11-02
1-n -1 5.0 ret number tdi for 包裝 print
#include<stdio.h>
int main()
{
int box1=11,box2=24;
float rate=55.0/0.5,weight,num1;
int num,i,j,m,n,k,t,min=11;
printf("put your number:");
scanf("%f",&weight);
num=rate*weight;
num1=rate*weight;
if((num1-num)*2>=1)num=num+1;
else num=num;
m=num/box1;
n=num/box2;
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
k=num-box1*i-box2*j;
if(k<0)break;
if(k<=min)min=k;
else min=min;
}
}
for(i=0;i<=m;i++)
{
for(j=0;j<=n;j++)
{
t=num-box1*i-box2*j;
if(t==min)break;
}
if(t==min)break;
}
printf("box1=%d,box2=%d,min=%d",i,j,min);
return 0;
}
作業6-1 巧克力盒子包裝