Best Answer

The Fibonacci sequence uses recursion to derive answers. It is defined as: F0 = 0

F1 = 1

Fn = F(n - 1) + F(n -2) To have this sequence printed by a php script use the following:

function fibonacci($n)

{

if($n 1)

return 1; //F1

else

return fibonacci($n - 1) + fibonacci($n - 2); //Fn

} This recursive function will print out the Fibonacci number for the integer n. To make it print out all the numbers in a particular set add this to your script.

for($i = 0; $i < 15; $i++)

{

echo fibonacci($i) . "<br />";

} So your final result would look like. <?php

function fibonacci($n)

{

if($n 1)

return 1;

else

return fibonacci($n - 1) + fibonacci($n - 2);

} for($i = 0; $i < 15; $i++)

{

echo fibonacci($i) . "<br />";

}

?>

Study guides

☆☆

Q: Can you write a program to print the Fibonacci series in php?

Write your answer...

Submit

Still have questions?

Related questions

write a program that display the Fibonacci series?

Just generate the Fibonacci numbers one by one, and print each number's last digit ie number%10.

Is this a homework question?

Fibonacci series has absolutely nothing to do with pointers.

write a program for Fibonacci series by using cunstructer ti initilised the value

Set two variables "a" and "b" to the starting number of the Fibonacci series, for example, 1 and 1. Then, repeatedly (i.e., in a loop) set: sum = a + b; b = a; a = sum; ... and print the sum (or equivalently, variable "a").

Exactly what do you mean by 'C program in Java'

write a program to print the series 1/12+1/22+.........+1/n2 ?

Where are the numbers that you want to sum.

a=0 b=1 c=0 For i=0 to whaterveryouwant print c c=a+b a=b b=c next i

//WAP to print fibonacci series using do-while loop.? using System; class Fibonacci { public static void Main() { int a=1,b=1; int sum=0; Console.Write("Enter Limit:"); int n=Int32.Parse(Console.ReadLine()); Console.Write(a); Console.Write(b); do { sum=a+b; a=b; b=sum; Console.Write(sum); } while(sum<n); } } By-Vivek Kumar Keshari

write a program to print A to Z on screen in c?

People also asked