Pages

How to Create Fibonacci Series upto N numbers in PHP

In this post, I will write a code to generate Fibonacci series using an iterative approach.

Fibonacci series of numbers such as 0,1,1,2,3,5,...And next is the summation of the last two previous numbers.

In this series, the first 2 number is 0, 1 or 1,1 and next number is the addition of previous two numbers.

 Logic of Fibonacci Series :-

i) Initialize first and second number.
first = 0 and  second = 1.

ii) Print both first and second number.

iii) Loop from index 2 to N. So third number is the sum of first and second.

Create PHP Function to Print Fibonacci Series :-

Let's develop a simple PHP function, which take a number as an argument. I am using an iterative approach to solve this problem.


 Now, print the series up to six numbers, you can pass any number as an argument.

Output:

 Check Below C,C++ Program to generate Fibonacci Series

Here, you can find the  PHP code to generate this series. Here is a C code to generate this series.


ethan

Phasellus facilisis convallis metus, ut imperdiet augue auctor nec. Duis at velit id augue lobortis porta. Sed varius, enim accumsan aliquam tincidunt, tortor urna vulputate quam, eget finibus urna est in augue.

No comments:

Post a Comment