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.
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.
0 comments:
Post a Comment