write a function to find maximum element of an array using recursion

3 views (last 30 days)
function mx = recursion_max(v)
n=size(v);
if size(v) <2
mx = v(1);
else mx = max(recursion_max(v(n-1)), mx );
end
end

Answers (1)

Ameer Hamza
Ameer Hamza on 10 Sep 2020
Edited: Ameer Hamza on 10 Sep 2020

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!