A program devise a recursive algorithm to find a2n, where a is a real number and n is a positive integer (hint: use the equality a2n+1 = (a^2n)^2
In this question, we have to find the recursive algorithm to find a2^n, where a is a real number and n is a positive integer.
Also we know the equality that a2^n+1 = (a2^n)2.
This implies that a2^n+1 =
(a2^n)2 = a2 . a2^n ,
for n>0.
For initial condition i.e n=0 , a2^1 = a2 = a*a . So to find recursive algorithm for a2^n, successively reduce it by using the recursive step .
The recursive algorithm to find a2^n is given below :
procedure power (a:real number, n:positive number)
if(n=1) then power(a,n) = a*a
else pow=power(a,n-1)
power(a,n) = pow * pow
If you have any doubt or query, then let me know in comment. If it helps, kindly give an upVote to this answer.
Get Answers For Free
Most questions answered within 1 hours.