Write an algorithm that generates the fibbonacci series as:
1,1,2,3, 5,…. N terms.
Answers
Explanation:
Program for Fibonacci numbers
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In mathematical terms, the sequence Fn of Fibonacci numbers is defined by the recurrence relation
Fn = Fn-1 + Fn-2
with seed values
F0 = 0 and F1 = 1.
First we can define Fibonacci series as follows:
The Fibonacci numbers are the numbers in the following integer sequence.
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ……..
In this series the later is the sum for previous two consecutive numbers.
Now, algorithm for Fibonacci series is as follows:-
Step 1: Start
Step 2: Declare variables N, N1, N2, N3, i.
Step 3: Read value of N from user.
Step 4: if N < 2, display message “Enter number > 2” and go to step 9.
Step 5: Initialize variables N1 = 0, N2 = 1,
i = 0
Step 6: Display N1, N2
Step 7: Compute N3 = N1 + N2
Step 8: Repeat following statements
until i < N - 2
Display N3
N1 = N2
N2 = N3
N3 = N1 + N2
i = i + 1
Step 9: Stop