How to resolve the algorithm Towers of Hanoi step by step in the PL/I programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Towers of Hanoi step by step in the PL/I programming language
Table of Contents
Problem Statement
Solve the Towers of Hanoi problem with recursion.
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Towers of Hanoi step by step in the PL/I programming language
Source code in the pl/i programming language
tower: proc options (main);
call Move (4,1,2,3);
Move: procedure (ndiscs, from, to, via) recursive;
declare (ndiscs, from, to, via) fixed binary;
if ndiscs = 1 then
put skip edit ('Move disc from pole ', trim(from), ' to pole ',
trim(to) ) (a);
else
do;
call Move (ndiscs-1, from, via, to);
call Move (1, from, to, via);
call Move (ndiscs-1, via, to, from);
end;
end Move;
end tower;
You may also check:How to resolve the algorithm Linear congruential generator step by step in the PL/I programming language
You may also check:How to resolve the algorithm Smith numbers step by step in the PL/I programming language
You may also check:How to resolve the algorithm Create a file step by step in the PL/I programming language
You may also check:How to resolve the algorithm Command-line arguments step by step in the PL/I programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the PL/I programming language