How To Implement PHP Code For Recursive Fibonacci Series

admin_img Posted By Bajarangi soft , Posted On 27-11-2020

In Fibonacci series we want to add previous two numbers to get next new number. For example, 0 1 1 2 3 5 8 13 21 34 Here, 0 + 1 = 1 1 + 1 = 2 3 + 2 = 5 3 + 5 = 8

How To Implement PHP Code For Recursive Fibonacci Series

Complete Code For Implement PHP Code For Recursive Fibonacci Series.

<!DOCTYPE html>
<html>
<head>
    <title>How To Implement PHP Code For Recursive Fibonacci Series</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<style>
    body {
        background: black;
    }
    .form-control {
        width: 80%;
    !important;
    }
</style>
<body>
<body>
<div class="container">
    <br/><br/>
    <div class="text-center">
        <h1 id="color" style="color: white;">Fibonacci Series</h1>
    </div>

    <div class="well">
        <form method="post">
            Enter a Number: <input class="form-control" type="text" name="number"><br><br>
            <input type="submit" class="btn btn-success" name="submit" value="Submit">
        </form>
        <?php
        if(isset($_POST['number']))
        {
            $number=$_POST['number'];

            function Fibonacci($number){
                if ($number == 0)// if number is equal 0 returns 0
                    return 0;
                else if ($number == 1)//if number is equal 1 returns 1
                    return 1;

                // Recursive Call to get the upcoming numbers
                else
                    return (Fibonacci($number-1) + Fibonacci($number-2));
            }


            for ($counter = 0; $counter < $number; $counter++){
                echo Fibonacci($counter),' ';
            }
        }
        ?>
    </div>
</div>
</body>
</html>

Related Post