Skip to content

Exponentiation

C++ recursive power

Same task in: JavaScript

Flowchart (ISO 5807)

YesNoStartInput base, expexp = 0Return 1EndReturn base·base^(exp − 1)EndFigure 1 — power

Source code

C++
int power(int base, int exp) {
    if (exp == 0) return 1;
    return base * power(base, exp - 1);
}

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

Language
C++
Constructs
recursive power
Topic
Recursion
Formats
Word, Visio, draw.io, PDF, SVG

Related examples