Skip to content

Perfect number

C++ sum of divisors

Flowchart (ISO 5807)

YesNoYesNoStartInput nsum = 0i = 1, n − 1, 1n mod i = 0sum = sum + isum = nOutput «Досконале»Output «Ні»EndFigure 1 — perfect

Source code

C++
void perfect(int n) {
    int sum = 0;
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            sum += i;
        }
    }
    if (sum == n) {
        cout << "Досконале";
    } else {
        cout << "Ні";
    }
}

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

Language
C++
Constructs
sum of divisors
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples