Basic Pascal Tutorial/Chapter 4/Solution/fr
Sent here from Solution 4/fr.
English · Français · Български · 中文(中国) · 日本語
Tutoriel de Pascal Objet : Sous-programmes / Solution de l'exercice
(* Auteur: Tao Yue
Date: 13 July 2000
Description:
Résout les Tours de Hanoï
Version:
1.0 - version originale
*)
program TowersofHanoi;
var
numdiscs : integer;
(********************************************************)
procedure DoTowers (NumDiscs, OrigPeg, NewPeg, TempPeg : integer);
(* Explanation of variables:
NumDiscs -- nombre de disque sur OrigPeg
OrigPeg -- numéro du piquet de la tour
NewPeg -- numéro du piquet où déplacer la tour
TempPeg -- piquet pour le stockage temporaire
*)
begin
(* Faites attention à la condition d'arrêt -- un disque *)
if NumDiscs = 1 then
writeln (OrigPeg, ' ---> ', NewPeg)
(* Faites attention à tous les autres cas *)
else
begin
(* En premier, déplacer tous les disques sauf le disque
du bas vers TempPeg, en utilisant NewPeg comme piquet
temporaire pour ce transfert *)
DoTowers (NumDiscs-1, OrigPeg, TempPeg, NewPeg);
(* Maintenant, déplacer le disque le plus bas depuis OrigPeg
vers NewPeg *)
writeln (OrigPeg, ' ---> ', NewPeg);
(* Finalement, déplacer les disques qui sont actuellement
sur TempPeg vers NewPeg, en utilisant OrigPeg comme
piquet temporaire pour ce transfert *)
DoTowers (NumDiscs-1, TempPeg, NewPeg, OrigPeg)
end
end;
(********************************************************)
begin (* Main *)
write ('Veuillez entrer le nombre de disques dans la tour ===> ');
readln (numdiscs);
writeln;
DoTowers (numdiscs, 1, 3, 2)
end. (* Main *)From the Free Pascal wiki, page "Basic Pascal Tutorial/Chapter 4/Solution/fr", as it stood on 2022-08-20 after a change by Kai Burghardt, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Edited on wiki.freepascal.org by 5 people, 2014–2022
From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.
| When | Who | What changed |
|---|---|---|
| E-ric | Created page | |
| Frigory | Refonte | |
| RedGuff | Ortho. (minor) | |
| Trev | Fixed syntax highlighting (minor) | |
| Trev | Text replacement - "Object Pascal Tutorial" to "Basic Pascal Tutorial" (minor) | |
| Kai Burghardt | Kai Burghardt moved page Solution 4/fr to Basic Pascal Tutorial/Chapter 4/Solution/fr: tidy up main name space: create subpage hierarchy for basic Pascal tutorial [cf. [[Special: PermaLink/149778#Clut... (minor) | |
| Kai Burghardt | bypass redirects [cf. discussion] | |
| Kai Burghardt | bypass language bar/categorization template redirect [cf. discussion] (minor) |
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
