php for 循环
3元一只公鸡,2元一只母鸡,0.5元一只小鸡 100元买100只 ,有多少种买法
for($g=1;$g<=33;$g++)
{
for($m=1;$m<=50;$m++)
{
$x=100- $g - $m;
if($g*3+$m*2+$x*1/2 == 100)
{
echo "公鸡".$g."只,母鸡".$m."只,小鸡".$x."只<br>";
}
}
}
蜘蛛8条腿,蝉6条腿,一对翅膀,蜻蜓6条腿,2对翅膀
三种昆虫有21只,共有140条腿,20对翅膀
问三种昆虫各多少只
for($z=1;$z<=17;$z++)
{
for($q=1;$q<=10;$q++)
{
$c = 21 - $z -$q;
if($z*8+$c*6+$q*6=140 && $c+$q*2=20)
{
echo "蜘蛛".$z."只,蝉".$c."只,蜻蜓".$q."只<br>";
}
}
}
It may have the strength, but the effort, struggle, worthy of the heart.

浙公网安备 33010602011771号