Skip to content

Fibonacci numbers

Go double recursion

Same task in: PythonRust

Flowchart (ISO 5807)

YesNoStartInput nn < 2Return nReturn fib(n − 1) + fib(n − 2)EndFigure 1 — fib

Source code

Go
func fib(n int) int {
    if n < 2 {
        return n
    }
    return fib(n-1) + fib(n-2)
}

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

Language
Go
Constructs
double recursion
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples