コード例 #1
0
ファイル: fibonacci.php プロジェクト: ksomemo/algorithm-1
function getFib($n)
{
    if ($n == 0) {
        return 1;
    }
    if ($n == 1) {
        return 2;
    }
    return getFib($n - 1) + getFib($n - 2);
}

<form>
    num1: <input type="text" name="num"/>
    <input type="submit">
</form>

<?php 
function getFib($n)
{
    return round(pow((sqrt(5) + 1) / 2, $n) / sqrt(5));
}
if (isset($_GET['num'])) {
    $n1 = htmlspecialchars($_GET['num']);
    for ($x = 1; $x <= (int) $n1; $x++) {
        echo getFib($x) . "\n";
    }
}