Skip to content

Count divisors

Go loop + counter

Flowchart (ISO 5807)

YesNoStartInput ncount = 0i = 1, n, 1n mod i = 0count = count + 1Return countEndFigure 1 — countDivisors

Source code

Go
func countDivisors(n int) int {
    count := 0
    for i := 1; i <= n; i++ {
        if n%i == 0 {
            count++
        }
    }
    return count
}

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

Language
Go
Constructs
loop + counter
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples