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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!