Skip to content

Factorial (recursion)

Python self-call → subroutine

Same task in: TypeScript

Flowchart (ISO 5807)

YesNoStartInput nn ≤ 1Return 1EndReturn n·factorial(n − 1)EndFigure 1 — factorial

Source code

Python
def factorial(n):
    if n <= 1:
        return 1
    return n * factorial(n - 1)

The editor opens with this code — change it and the chart redraws.

Language
Python
Constructs
self-call → subroutine
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples