Fibonacci Series Program in PHP

Advertisements

Prev Tutorial Next Tutorial

Fibonacci Series Program in PHP

The simple concept to find fibonacci series is; add two previous term and get next term. Example of Fibonacci Series is; 0 1 1 2 3 5.

Fibonacci Series Program in PHP

<?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

Fibonacci Series Program in PHP

<?php

define('NUM',11);
$a = 0;
$b = 1;

echo "$a $b "; // 0 1

for($i=1   ; $i<= NUM-2 ;  $a=$b, $b=$c, $i++ ) 
{
  echo $c = $a+$b;
  echo " ";
}

?>

Output

	
0 1 1 2 3 5 8 13 21 34 55

Prev Tutorial Next Tutorial

Advertisements

Buy This Ad Space @$20 per Month, Ad Size 600X200 Contact on: hitesh.xc@gmail.com or 8076671483

Pure VPN Privide Lowest Price VPN Just @ $1.65. Per Month with Non Detected IP Lowest Price Non Detected IP VPN

Magenet is best Adsense Alternative here we earn $2 for single link, Here we get links ads. Magenet

Download Projects

Google Advertisements


Buy Websites 9999595223

Buy Fresh and Payment Receive Media.net Account with Website. Contact on: hitesh.xc@gmail.com or 9999595223 Try this Keyword C++ Programs

Advertisements