Flowchart examples · Programming and algorithms

Flowchart to find the factorial of a number

Multiply 1 × 2 × … × N with a loop and a counter, reject negative input, and print the result. Traced for N = 5.

Use this template Describe your own version

Factorial of N

Factorial of NYesNoYesNoStartRead NN < 0?Print error: nofactorialfact = 1, i = 1i ≤ N?fact = fact × ii = i + 1Print factEnd
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 < 0?"}
  err[/"Print error: no factorial"/]
  init["fact = 1, i = 1"]
  d1{"i ≤ N?"}
  mul["fact = fact × i"]
  inc["i = i + 1"]
  out[/"Print fact"/]
  e(["End"])
  s --> in
  in --> d0
  d0 -->|Yes| err
  d0 -->|No| init
  init --> d1
  d1 -->|Yes| mul
  d1 -->|No| out
  mul --> inc
  inc --> d1
  out --> e
  err --> e

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

About this factorial flowchart

The factorial of a non-negative whole number N, written N!, is the product of all whole numbers from 1 to N. So 5! = 1 × 2 × 3 × 4 × 5 = 120, and by definition 0! = 1. Factorials of negative numbers are not defined.

The flowchart is the standard introduction to loops. Two variables are set before the loop starts: fact, which holds the running product and starts at 1, and i, the counter, which also starts at 1. The decision i ≤ N controls the loop. Inside the loop, fact is multiplied by i and i goes up by one, then the arrow returns to the decision. When i passes N, the loop exits and fact is printed.

Starting fact at 1 rather than 0 matters: multiplying by 0 would make every answer 0. Starting at 1 also handles 0! correctly, because the loop never runs and the chart prints 1.

Step by step

  1. Input. Read N.
  2. Validate. If N is negative, print an error and end; factorial is not defined for negative numbers.
  3. Initialize. Set fact = 1 and i = 1 in one process box.
  4. Loop test. Is i ≤ N? If yes, enter the loop body; if no, exit to the output.
  5. Loop body. Multiply fact by i, then add 1 to i, and return to the test.
  6. Output. Print fact and end.

How to make it in flow-chart.io

  1. Start from the example. Press "Use this template" to open this exact factorial 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 factorial of a number?
Start, read N, reject negatives, set fact = 1 and i = 1, then loop while i ≤ N: multiply fact by i and add 1 to i. When the loop ends, print fact and stop.
Why does fact start at 1?
Because it is a product. Starting at 0 would make every result 0. Starting at 1 also gives the correct answer for 0!, which is 1.
What symbol is used for the loop?
There is no separate loop symbol in a basic flowchart. A loop is a decision (diamond) with an arrow that returns to an earlier step. Some textbooks use a hexagon (preparation symbol) for a for-loop header.
How do I write it in Python?
fact = 1, then for i in range(1, n + 1): fact *= i, then print(fact). Python's integers grow as needed, so large N works.
Can I edit this factorial flowchart?
Yes. Press Use this template to open it in the editor with a free account.

Related

Prime number flowchartFlowchart to check even or odd numberFlowchart to find the largest of three numbersLeap year flowchartFibonacci series 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