Thursday, January 21, 2016

PHP FIBONACCI SERIES PROGRAM: Display A Fibonacci Series Code

Hi there! The following tutorial will introduce you to one of the most common problems encountered in programming subjects. Later on, I will provide set of activities and quizzes for you to practice on to improve your programming skills.

Fibonacci series is just one of the exercises given by most programming instructors. Some other exercises are the following:

  1. Create a simple php calculator
  2. Celsius to Fahrenheit Temperature Converter
  3. Identify if odd or even number
  4. Display numbers using a for loop
  5. Solve for the area of a triangle

and many more. These are just some of the activities that I posted here in my blog. You can visit the links if you want.

Fibonacci series is achieved by adding the first and second value to solve for the third number. And then the 2nd and third to solve for the 4th number and so on and forth. The series starts with 0 and 1 and then 1, 3, 5, 8, 13 and so on.  To be able to achieve this, we need to use to looping statement. In my example, I used the while loop.

The following code will display a fibonacci series and will stop until the 10th number. Your $i there will serve as a counter and your $stopper is where the loop will stop.

PHP Code Fibonacci Series

echo $b."<br>";

while ($i<$stop)
echo $sum;
echo "<br>";

Output Fibonacci Series

Try Fibonacci Series Program in PHP here live!

PHP  FIBONACCI SERIES PROGRAM: Display A Fibonacci Series Code

No comments:

Post a Comment