Fibonacci Series Flowchart
Fibonacci series flowchart: keep the last two terms in a and b, print a, then slide the pair forward with c = a + b. With a trace of the first 7 terms (0 1 1 2 3 5 8), pseudocode, and tested Python, C and Java code.
Fibonacci series flowchart: keep the last two terms in a and b, print a, then slide the pair forward with c = a + b. With a trace of the first 7 terms (0 1 1 2 3 5 8), pseudocode, and tested Python, C and Java code.
Study guide
In the Fibonacci series each term is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13, and so on. A Fibonacci series flowchart only ever remembers two numbers, a and b; on each pass it prints a, works out the next term c = a + b, and slides the window one step along.
Think of a and b as two footprints walking up the series: the back foot always steps to where the front foot was.
i counts how many terms have been printed, starting at term 1.n terms are printed and the program ends.a.b. A third variable is needed because a is about to be overwritten.b into a first, then c into b.Each row is one test of i <= n?. The last three columns show the values after the step is done.
| i | i <= n? | Printed a | c = a + b | new a | new b |
|---|---|---|---|---|---|
| 1 | Yes | 0 | 1 | 1 | 1 |
| 2 | Yes | 1 | 2 | 1 | 2 |
| 3 | Yes | 1 | 3 | 2 | 3 |
| 4 | Yes | 2 | 5 | 3 | 5 |
| 5 | Yes | 3 | 8 | 5 | 8 |
| 6 | Yes | 5 | 13 | 8 | 13 |
| 7 | Yes | 8 | 21 | 13 | 21 |
| 8 | No | nothing | not run | not run | not run |
Output: 0 1 1 2 3 5 8. Notice the loop calculates two terms (13 and 21) that it never prints. That is fine: it is the price of keeping the loop simple.
READ n
a = 0
b = 1
FOR i = 1 TO n
PRINT a
c = a + b
a = b
b = c
NEXT i
n = int(input())
a = 0
b = 1
i = 1
while i <= n:
print(a, end=" ")
c = a + b
a = b
b = c
i = i + 1
print()
#include <stdio.h>
int main(void) {
int n;
scanf("%d", &n);
long long a = 0, b = 1, c;
for (int i = 1; i <= n; i++) {
printf("%lld ", a);
c = a + b;
a = b;
b = c;
}
printf("\n");
return 0;
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
long a = 0, b = 1, c;
for (int i = 1; i <= n; i++) {
System.out.print(a + " ");
c = a + b;
a = b;
b = c;
}
System.out.println();
}
}
7
0 1 1 2 3 5 8
All three programs were compiled and run with the input 7 before publishing. Each prints the terms on one line with a trailing space after the last one.
b = c before a = b makes a and b equal, and the series turns into 0, 1, 2, 4, 8 (doubling). Copy b into a first.a = b then b = a + b uses the new a, which is wrong. Either use c, or in Python write a, b = b, a + b, which reads both old values first.i at 0 with the test i <= n prints n + 1 terms. Start at 1 with <=, or at 0 with <.a = 2 and b = 3.
Read the third row of the trace: the new a is 2 and the new b is 3. The next term printed will be 2.
Replace the counter with a value test: the diamond becomes a < 50?, and Read n, i = 1 and Set i = i + 1 are removed.
a = 0
b = 1
WHILE a < 50
PRINT a
c = a + b
a = b
b = c
ENDWHILE
It prints 0 1 1 2 3 5 8 13 21 34.
a, b = 0, 1
for i in range(7):
print(a, end=" ")
a, b = b, a + b
print()
The right-hand side b, a + b is worked out completely before anything is assigned, so the old a is still used. That removes the need for a third variable.
| Symbol | Shape to draw on paper | Where it appears here | Why |
|---|---|---|---|
| Terminator | Rounded box | Start and End | One entry, one exit. |
| Input/output | Parallelogram | Read n and Print a | Data in and each term out. |
| Process | Rectangle | The setup box, Set c = a + b, the shift and the update | Each one calculates or moves values. |
| Decision | Diamond | i <= n? | Decides whether another term is needed. |
| Loop | A decision whose flow line returns to an earlier step | The arrow from Set i = i + 1 back to i <= n? | Repeats the print and shift once per term. |
In the interactive diagram every step is a labelled card: the small word above each step names its kind (process, decision or data). When you draw this flowchart by hand, use the standard shapes in the table. The full list is on the flowchart symbols page.
Each link opens the editor with a prompt already filled in. Change the wording, then generate your own flowchart.
Download the Fibonacci Series Flowchart as a PNG or SVG, or open it in the studio to edit your own copy. To draw a similar flowchart from a description, use the flowchart generator; for notation and a step-by-step walkthrough, read how to make a flowchart; and browse more flowchart examples for related layouts.
Type any system, process, or schema in plain English. ChartCraft will draw it in seconds.