# Recursive algorithm

• Nov 5th 2008, 12:48 PM
dh214
Recursive algorithm
Devise a recursive algorithm to find a^(2^n) n where a is a real number and n
is a positive integer.

This is a bit tricky
• Nov 6th 2008, 04:50 AM
CaptainBlack
Quote:

Originally Posted by dh214
Devise a recursive algorithm to find a^(2^n) n where a is a real number and n
is a positive integer.

This is a bit tricky

Only for small values of tricky.

$a^{2^n}=(a^{2^{n-1}})^2$

so:

Code:

```function aToThe2n(a,n)   if n==1     rv=a^2   else     rv=(aToThe2n(a,n-1))^2   endif   return rv endfunction```
CB