This problem was fun. I was able to find a better way to solve beat my own solution. Not the best way though. But lot better.
@Alireza yarmohammadi: your comment was deleted as it revealed an answer to the problem.
In response to the question you asked, though, your function returns m, which is not the complete answer. The last line in your function displays the correct result, but assigns it to ans, not m.
185 Solvers
Who knows the last digit of pi?
565 Solvers
Find nearest prime number less than input number
277 Solvers
Celsius to Fahrenheit converter
404 Solvers
343 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!