int power(int a, int b) { if (b == 0) return 1; if (b == 1) return a; if (b<0) return 1/power(a, -b); // a should not be 0 int x = power(a, b/2); return b&1? x*x*a:x*x; }
Software Engineer by Profession, RIA Enthusiast, Passionate about Technologies, Another King waiting for his kingdom...
If you would like to get in touch with me, please leave a comment with your mail id and I promise that I will get back to you.
No comments:
Post a Comment