Important Notice:

Fibonacci Sequence Generation

Fibonacci Sequence Generation

4 views 1 min read

Fibonacci Sequence Generation :- Question:-

Write an algorithm and flowchart to generate the Fibonacci sequence up to N terms.

Example:-

N = 7

Fibonacci Sequence:

0, 1, 1, 2, 3, 5, 8

Logic / Explanation:-

A = 0 → Store the first term.

B = 1 → Store the second term.

C = A + B → Calculate the next term.

A = B → Move the second term to the first position.

B = C → Move the next term to the second position.

Solution:-

Algorithm: Fibonacci Sequence Generation

Step 1: Start.
Step 2: Input the number of terms N.
Step 3: Set A = 0, B = 1, and i = 1.
Step 4: Display A.
Step 5: Set C = A + B.
Step 6: Set A = B.
Step 7: Set B = C.
Step 8: Set i = i + 1.
Step 9: Repeat Steps 4 to 8 while i <= N.
Step 10: Stop.

Related Notes