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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started