I made a recursive code to print a tree but the tree is printed backwards
Ältere Kommentare anzeigen
function Affarbre2(n,N)
if n>0
for j = 1:(N+2)
if (abs(N-j))<n
fprintf('*');
else
fprintf('
end
end
disp(' ')
Affarbre2(n-1,N)
end
Antworten (1)
Affarbre_right(5,5)
Affarbre_left(5,5)
function Affarbre_right(n,N)
if n > 0
for j = 1:(N+2)
if abs(N+2-j) < n
fprintf('*');
else
fprintf(' ');
end
end
% disp(' ')
fprintf('\n');
Affarbre_right(n-1,N);
end
end
function Affarbre_left(n,N)
if n > 0
for j = 1:(N+2)
if abs(1-j) < n
fprintf('*');
else
fprintf(' ');
end
end
% disp(' ')
fprintf('\n');
Affarbre_left(n-1,N);
end
end
Kategorien
Mehr zu Structures finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!