Created
June 16, 2019 11:24
-
-
Save adist98/87a0abe076cfef52d6e2ab3924127c24 to your computer and use it in GitHub Desktop.
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
/* Function to calculate x raised to the power y in O(logn)*/ | |
int power(int x, unsigned int y) | |
{ | |
int temp; | |
if( y == 0) | |
return 1; | |
temp = power(x, y/2); | |
if (y%2 == 0) | |
return temp*temp; | |
else | |
return x*temp*temp; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function calculates only positive powers.