I made a recursive code to print a tree but the tree is printed backwards
Afficher commentaires plus anciens
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
Réponses (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
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!