You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
438 B
PHTML
30 lines
438 B
PHTML
5 years ago
|
<?php
|
||
|
|
||
|
function printFibonacci($n)
|
||
|
{
|
||
|
|
||
|
$first = 0;
|
||
|
$second = 1;
|
||
|
|
||
|
echo "Fibonacci Series \n";
|
||
|
|
||
|
echo $first.' '.$second.' ';
|
||
|
|
||
|
for($i = 2; $i < $n; $i++){
|
||
|
|
||
|
$third = $first + $second;
|
||
|
|
||
|
echo $third.' ';
|
||
|
|
||
|
$first = $second;
|
||
|
$second = $third;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/* Function call to print Fibonacci series upto 6 numbers. */
|
||
|
|
||
|
printFibonacci(6);
|
||
|
|
||
|
?>
|
||
|
/* Output Fibonacci Series 0 1 1 2 3 5 */
|