Flowchart examples · Programming and algorithms

Flowchart to print the Fibonacci series

Keep the last two numbers in a and b, print a, slide both forward, and repeat N times. Traced for N = 7.

Use this template Describe your own version

Print the first N Fibonacci numbers

Print the first N Fibonacci numbersYesNoYesNoStartRead NN < 1?Print error: N must be 1or morea = 0, b = 1, i = 1i ≤ N?Print anext = a + ba = b, b = nexti = i + 1End
Use this template →Opens this exact diagram in the editor, every box and arrow editable. Free account; no AI credits used.

A worked example to adapt. Rename steps, add branches and owners to match how your team actually works.

Edit the steps to match your process. The free preview (no sign-up) drafts up to 8 main steps; add branches and the remaining steps in the editor.
Mermaid source for this diagram
flowchart TD
  s(["Start"])
  in[/"Read N"/]
  d0{"N < 1?"}
  err[/"Print error: N must be 1 or more"/]
  init["a = 0, b = 1, i = 1"]
  d1{"i ≤ N?"}
  out[/"Print a"/]
  next["next = a + b"]
  shift["a = b, b = next"]
  inc["i = i + 1"]
  e(["End"])
  s --> in
  in --> d0
  d0 -->|Yes| err
  d0 -->|No| init
  init --> d1
  d1 -->|Yes| out
  d1 -->|No| e
  out --> next
  next --> shift
  shift --> inc
  inc --> d1
  err --> e

Paste into any Markdown tool that renders Mermaid, such as GitHub.

About this fibonacci series flowchart

The Fibonacci series starts 0, 1, and every number after that is the sum of the two before it: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 and so on. Printing the first N terms is a standard exercise because it needs a loop and two variables that move forward together.

The flowchart keeps the two most recent numbers in a and b. Each pass prints a, adds a and b to get the next number, then slides the window forward: a takes b's value and b takes the new number. A counter i stops the loop after N terms.

The order of the two assignments matters. If you set a = b first and then compute a + b, you add the wrong pair. Saving the sum in next before moving a and b, as the diagram does, avoids that mistake and is easy to check in a trace.

Step by step

  1. Input. Read N, the number of terms to print.
  2. Validate. If N is less than 1 there is nothing to print, so print an error and end.
  3. Initialize. Set a = 0 and b = 1 (the first two terms) and the counter i = 1.
  4. Loop test. While i ≤ N, print the current term; when i passes N, the loop ends.
  5. Next term. Compute next = a + b, then set a = b and b = next.
  6. Count. Add 1 to i and go back to the loop test.

How to make it in flow-chart.io

  1. Start from the example. Press "Use this template" to open this exact Fibonacci flowchart in the editor, or edit the text in the generator box and press Generate for a free preview without signing up.
  2. Match your program. Rename the input, process and output boxes so they use the same variable names as your code. Keep one action per box.
  3. Check every branch. Trace each diamond with a test value for the Yes exit and one for the No exit, and make sure both reach the end oval.
  4. Share or export. Share a read-only view link with a classmate or reviewer. Downloads as PNG, SVG or PDF are part of Flow Pro (see pricing).

Tips

Frequently asked questions

What is the flowchart for the Fibonacci series?
Start, read N, set a = 0, b = 1 and i = 1, then loop while i ≤ N: print a, compute next = a + b, set a = b and b = next, and add 1 to i. When the loop ends, stop.
Why do we need a third variable?
Because a and b both change in the same step. Saving a + b in next first means the old values are still available when you move them forward. Without it, one of them is overwritten too early.
Does the Fibonacci series start with 0 or 1?
Both conventions exist. Many programming courses start with 0, 1. Others start with 1, 1. Change the starting values in the initialize box to match your course.
How do I write it in Python?
a, b = 0, 1, then for _ in range(n): print(a); a, b = b, a + b. Python's tuple assignment updates both at once, so it needs no extra variable.
Can I edit this Fibonacci flowchart?
Yes. Press Use this template to open it in the editor with a free account, or type your own steps into the text to flowchart tool.

Related

Factorial flowchartPrime number flowchartFlowchart to check even or odd numberBinary search flowchartFlowchart symbolsHow to make a flowchartText to flowchart toolAll flowchart examples

Build it from your own words

Describe your process and get an editable diagram. Free to build and edit; Flow Pro adds downloads and unlimited projects.

Start free See pricing