A recursive definition of an where a is an integer and n is a non-negative integer
follows:
a^nif=1 if n = 0
a^n=a*a^(n-1) if n>0
Write a recursive function called mypower, which receives a and n and returns the
value of an by implementing the previous definition. Note that the program should
not use ^ operator anywhere; this is to be done recursively instead! Test the
function.
I tried this one but cant work
function power=mypower(a,n)
if n==0
power(a,n)=1;
else
power(a,n)=a*mypower(a,n-1);
Thanks
end
power = 1instead. – Memming Feb 24 '14 at 00:22