Skip to content

Factorial (loop)

C++ for with accumulation

Same task in: JavaScript

Flowchart (ISO 5807)

StartInput nr = 1i = 2, n, 1r = riReturn rEndFigure 1 — fact

Source code

C++
long fact(int n) {
    long r = 1;
    for (int i = 2; i <= n; i++) {
        r *= i;
    }
    return r;
}

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

Language
C++
Constructs
for with accumulation
Topic
Loops
Formats
Word, Visio, draw.io, PDF, SVG

Related examples