Sunday, June 2, 2013

Fibonacci Series

Question: We have to ask user to enter the no. of terms he/she wants, and series should be generated accordingly.

Answer: Copy the below code and paste it into "your.php" file. After done this you will just need to run "your.php" file in browser and you will get the output successfully.
<!DOCTYPE html>
<html xmlns="">
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Fibonancy series</title>
        <h1><center>Fibonancy series</center></h1>
            $a = 0;
            $b = 1;
            $sum = 0;
        <form action="<?php echo $_SERVER['PHP_SELF']; ?>"  method="post">
            Enter number of terms:<input type="text" name="name">
            <input type="submit" name="submit" value="OK"><br>
            if (isset($_POST['submit'])) {
                $term = $_POST['name'];
                echo "$a,$b,";
                while ($term - 2) {
                    $sum = $a + $b;
                    $a = $b;
                    $b = $sum;
                    echo $sum . ",";

No comments:

Post a Comment