I made a recursive code to print a tree but the tree is printed backwards

Respuestas (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

Categorías

Etiquetas

Preguntada:

el 4 de Mzo. de 2022

Respondida:

el 4 de Mzo. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by