Skip to content

Instantly share code, notes, and snippets.

@rgrig
Created July 17, 2014 06:09
Show Gist options
  • Save rgrig/9ab076b294fe838f088d to your computer and use it in GitHub Desktop.
Save rgrig/9ab076b294fe838f088d to your computer and use it in GitHub Desktop.
int power(int x, unsigned int y) {
if (y == 0) return 1;
if (y == 2) return x * x;
if (y&1) return x * power(power(x, y/2),2);
return power(power(x, y/2),2);
}
@rgrig
Copy link
Author

rgrig commented Jul 17, 2014

there are better ways ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment