Question: I have the problem: In MatLab, create a recursive function to print the digits of a number backwards. For example, given the number 752, it
I have the problem:
In MatLab, create a recursive function to print the digits of a number backwards. For example, given the number 752, it should print 2 then 5 then 7. Once you get that working, have it return an array, where each call to the recursive function adds another digit to the array, e.g. 2, 5, 7.
I have the recursive working to print the number out but not as an array. Any help would be great.
My Code:
function revNum = rev_Val(myInput) out=0; while myInput > 0 temp = mod(myInput,10); out = 10*out+temp; myInput = rev_Val((myInput-temp)/10); end revNum = out; end
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
