How to make Fibonacci series by PHP programming

Fibonacci series is a such kind of series of numbers in which the current number is the addition of previous two numbers. It is a mathematical series. Today we will see How to make Fibonacci series by PHP programming without using array or function
Procedure:

  1. We will collect the 1st number, 2 number and the length of series by HTML.
  2. Then we will print them serially.
  3. Add them. It will be the third number.
  4. Print the third number and generate the next number.
  5. Use a loop till the length ends. It will generate the Fibonacci Sequence.
Now see the code:

First generate the HTML to read data.

<form action='?' method='POST'>
Enter the startig number: <input name="start" /><br/>
Enter the second number: <input name="second" /><br/>
Enter the series length: <input name="length" /><br/>
<input type='submit' value='Generate Fibonacci'/>
</form>

Now do the operations.

<?php 
if(isset($_POST['start']))
{
 $start = $_POST['start'];
 $length = $_POST['length'];
 $second = $_POST['second'];
 print "<u><b>The generated fibonacci series is:</b></u> " . $start ."," . $second;
 $now = $start + $second;
 for($i=3;$i<=$length;$i++)
 {
  print "," . $now;
  $cache = $now;
  $now = $now + $second;
  $second = $cache;
 }
 print "...";
 
}
?>



Happy programming!




Related Posts
Previous
« Prev Post