MATLAB: How do i create a recursive function that gives the number of digits in an integer? i.e. does the same that length function does in MATLAB

function

function r = length_of(n)
end
it seems to be easy but right now i'm stuck with it

Best Answer

As Wayne mentioned, recursivity in unnecessary, but if you had to implement a recursive function, you could have built something like:
function r = length_of(n)
if n < 10
r = 1 ;
else
r = 1 + length_of(n/10) ;
end
end
Related Question