Skip to content

Anti-diagonal sum

Go loop over diagonal

Flowchart (ISO 5807)

StartInput a, ns = 0i = 0, n − 1, 1s = s + a[i][n − 1 − i]Return sEndFigure 1 — antiDiagonal

Source code

Go
func antiDiagonal(a [][]int, n int) int {
    s := 0
    for i := 0; i < n; i++ {
        s += a[i][n-1-i]
    }
    return s
}

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

Language
Go
Constructs
loop over diagonal
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples