编写程序,求解鸡兔同笼问题?

2024-11-21 18:28:00
推荐回答(2个)
回答1:

dim x,y,h,f
h=inputbox("请输入头数","")
f=inputbox("请输入脚数","dfgsg")
msgbox "鸡=" & f/2-h & " 兔=" & 2*h-f/2

回答2:

#includeint InputBox()
{
int a;
scanf("%d",&a);
return a;
}int main()
{
int x,y,h,f;
printf("输入鸡和兔的总头数:");
h = InputBox();
printf("输入鸡和兔的总脚数:");
f = InputBox();
x = (4*h-f)/2;
y = (f-2*h)/2;
if(x+y == h && 2*x+4*y == f && x >= 0 && y >= 0)
{
printf("笼中鸡有%d只\n",x);
printf("笼中兔有%d只\n",y);
}
else
printf("无法得到非负整数解\n");
return 0;
}