Last active
November 4, 2015 03:26
-
-
Save not-for-me/2c02e41b6f28bd71bc00 to your computer and use it in GitHub Desktop.
tail recursion version: two's exponential function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int _twoExponential(int exponent, int acc) { | |
if ( exponent == 0 ) { | |
return acc; | |
} | |
acc *= 2; | |
return _twoExponential(--exponent, acc); | |
} | |
int exponential(int num) { | |
return _twoExponential(num, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment