Custom Search

Monday, April 18, 2011

python Recursive function to find power


def power(a, b):
if b==0:
return 1
return a*power(a, b-1)

print "----power---",power(6,2)


#OR


def power(a, b):
if b==0:
return 1
result = a*power(a, b-1)
return result

print "----power---",power(2,5)


Output
=======
----power--- 36
----power--- 32

No comments:

Post a Comment