1、一球从100米高度落下,每次落地后反跳回原高度的一半,再落下。编程求它第10次落地时,共经过距离为多少米?第10次的反弹有多高?
2、将100元钱兑换成10元,5元,1元,编程求不同的兑换数。要求每种兑法中都要有10元,5元,1元。
3、编程求解母牛问题。若-头母牛,从出生起第四个年头开始每年生一头母牛 ,此规律,第n年时有多少头母牛?
4、编程求所有的 “水仙花数(narcissus number)”。所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身。例如,153是水仙花数,因为153=1³+5³+3³。

解决方案 »

  1.   

    1、弹球 $jumpHeight = 100;
            $nextBegin = 100;
            for($i=1; $i <= 10; $i++) {
                $nextBegin = $nextBegin / 2;
                $jumpHeight += $nextBegin;
            }
            echo $jumpHeight;
            echo '<hr/>';
            echo $nextBegin;
      

  2.   

    for ($i = 1; $i < 10; $i++) {
    for ($j = 1; $j < 20; $j++) {
    for ($h = 1; $h < 100; $h++) {
    if (($i * 10 + $j * 5 + $h * 1) == 100) {
    echo '10元:' . $i . '个;5元' . $j . '个;1元' . $h . '个<br />'; 
    }
    }
    }
    }
      

  3.   

    echo heigth(100, 10);
    function heigth($heigth, $length) {
    if ($length <= 0) {
    return $heigth;
    }
    $heigth = $heigth / 2;
    $length--;
    return heigth($heigth, $length);
    }