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:
First generate the HTML to read data.
Now do the operations.
Note: This procedure can be used in another programming languages. You have to just change the commands and operators their.
Happy programming!
Procedure:
- We will collect the 1st number, 2 number and the length of series by HTML.
- Then we will print them serially.
- Add them. It will be the third number.
- Print the third number and generate the next number. Add this number with the previous sum.
- Use a loop till the length ends. It will generate the Fibonacci Sequence.
- Print them.
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 fibonacci series is:</b></u> " . $start ."+" . $second; $now = $start + $second; $sum = $now; for($i=3;$i<=$length;$i++) { print "+" . $now; $cache = $now; $sum = $sum + $now; $now = $now + $second; $second = $cache; } print "=$sum"; } ?>
Note: This procedure can be used in another programming languages. You have to just change the commands and operators their.
Happy programming!