answersLogoWhite

0


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 />";

}

?>

User Avatar

Wiki User

โˆ™ 2008-04-12 20:36:07
This answer is:
User Avatar
Study guides

What is a programming language

What does DOS stand for

What is a software that is distributed for free

What is application software

โžก๏ธ
See all cards
3.79
โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…
19 Reviews

Add your answer:

Earn +20 pts
Q: Can you write a program to print the Fibonacci series in php?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to display the Fibonacci series?

write a program that display the Fibonacci series?


Write a java program to print the last digit in Fibonacci series?

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


Write a program to print the Fibonacci series in php upto input value using recursive function?

Is this a homework question?


Write a program to generate the Fibonacci Series using pointers?

Fibonacci series has absolutely nothing to do with pointers.


Write a program for Fibonacci series by using copy constructor in c plus plus?

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


Write a program to generate the fibonacci series in java?

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").


Write a c program Fibonacci series using for loop in java?

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


Write a C program to print the following series 112 122 . 1n2?

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


Write a program to genarate Fibonacci series upto sum numbers?

Where are the numbers that you want to sum.


Write a program to print the Fibonacci series 0 1 1 2 3 5 8-------20?

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


Write a program in C Sharp to print Fibonacci series using while loop?

//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&lt;n); } } By-Vivek Kumar Keshari


Write an assembly language program to print a to z on screen?

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

People also asked