MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / power

Function power

Examples/NoModules/Chapter 08/Ex8_16.cpp:16–21  ·  view source on GitHub ↗

Recursive function to calculate x to the power n

Source from the content-addressed store, hash-verified

14
15// Recursive function to calculate x to the power n
16double power(double x, int n)
17{
18 if (n == 0) return 1.0;
19 else if (n > 0) return x * power(x, n - 1);
20 else /* n < 0 */ return 1.0 / power(x, -n);
21}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected