← All examples

Count divisors

Go Loops

loop + counter

Flowchart (ISO 5807)

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

Source code

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