Algorithm and Flowchart to Calculate Fibonacci series up to n

[228321 views]




What is a Fibonacci Series?


Pseudocode for Fibonacci series

A series of numbers in which each number is the sum of the two preceding or previous numbers is called Fibonacci Series.

For example, Fibonacci series upto 7 numbers is 1, 1, 2, 3, 5, 8, 13.
In above example, first 2 numbers (1, 1) are printed directly as there are no preceding numbers. But after that, i.e the 3rd number (2) is the sum of 1st and 2nd number (1+1=2). Similarly to get 4th number, we add 2nd and 3rd number. (i.e., 1+2=3). You can use this pattern to find fibonacci series upto any number.

Mathematical expression to find Fibonacci number is :

Fn=Fn-1+Fn-2

i.e. To get nth position number, you should add (n-2) and (n-1) position number.

Flowchart for Fibonacci Series Algorithm:


Flowchart for Fibonacci Number series for n numbers
Remove WaterMark from Above Flowchart

Pseudocode for Fibonacci Series upto n numbers:

Step 1: Start Step 2: Declare variable a, b, c, n, i Step 3: Initialize variable a=0, b=1 and i=2 Step 4: Read n from user Step 5: Print a and b Step 6: Repeat until i<=n : Step 6.1: c=a+b Step 6.2: print c Step 6.3: a=b, b=c Step 6.4: i=i+1 Step 7: Stop

So, if a user Enters 5,then n=5,
Variables a and b are initialized to 0 and 1 respectively. In Step 5, We directly print a and b, So the Output till Step 5 is-
0 1

In Step 6, value of "i" is 2 as the first two numbers (0, 1) are already printed. Now for every iteration of "i", we add a and b, so variable "c" now becomes 1 (i.e. 0+1). Then the value of "c" is printed. So Output now becomes -
0 1 1

In Step 6.3, we move 2nd last value (which is stored in variable "b") to variable "a" and last value (which is stored in variable "c") to b. So Now,
a=1, b=1

In Step 6.4, Value of "i" is incremented by 1(i.e. i=i+1 ) and iteration again continues until value of "i" is less than user entered number "n".

So, For i=3, Again following steps 6.1 to 6.4, Output will be-
0 1 1 2

So, For i=4, Again following steps 6.1 to 6.4, Output will be-
0 1 1 2 3

So, For i=5, Again following steps 6.1 to 6.4, Output will be-
0 1 1 2 3 5

For i=6, condition i less than n becomes false as (6<=5) is false. Hence the Final Output will be -
0 1 1 2 3 5

                 



Having Difficulty understanding above Algorithm and Flowchart? Buy my Personal Notes



Are You Good enough in Algorithms? Prove it!



Comments

1 comment
  • asif

    hoiche flowchart? paren na dite ashen kno?





Search
Get Answers to your Programming Questions


Recommended Deals ends in








Test Your Skills:

Search Tags

    Pseudocode for Fibonacci Series

    Fibonacci Series Algorithm

    What is Fibonacci Series

    Print Fibonacci series upto n algorithm

    calculate fibonacci series pseudocode

    Algorithm for Fibonacci Series

    fibonacci series flowchart