LoginSignup
0
0

More than 5 years have passed since last update.

phpで問題を解いてみた【3】

Posted at

問題

フィボナッチ数列出力

自分なりの回答

<?php
// Here your code !
function fivonachi($target){
    $i = 1;
    $y = 0;
    $r = 1;
    $answer = 0;
    if($target < 2){
        return $target;
    }
    do{
        $answer = $y + $i;
        $y = $i;
        $i = $answer;
        $r = $r + 1;
    }while($r <> $target);
    return $answer;
}
var_dump(fivonachi(1));
?>


まとめ

今回は1つのパターンのみですが、いろいろな方法で書くのも面白いですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0