Quantcast
Channel: BSDnexus
Viewing all articles
Browse latest Browse all 17

recursion power of

$
0
0

A book I was reading suggested I write a recursive function that calculated a power of a number. Here’s my attempt – comments and suggestions welcome:

double powerup( double num, double powr)
{
    if ( powr < 0 || num < 0 )
        return 0;

    if ( powr == 1 )
        return num;

    powr--;
    return num * powerup(num, powr);
}

Viewing all articles
Browse latest Browse all 17

Trending Articles