Skip to content

Sum of proper divisors

C# loop + condition

Flowchart (ISO 5807)

YesNoStartInput ns = 0i = 1, n / 2, 1n mod i = 0s = s + iReturn sEndFigure 1 — Program.SumProperDivisors

Source code

C#
class Program {
    static int SumProperDivisors(int n) {
        int s = 0;
        for (int i = 1; i <= n / 2; i++) {
            if (n % i == 0) {
                s = s + i;
            }
        }
        return s;
    }
}

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

Language
C#
Constructs
loop + condition
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples