Advanced Pascal Programming Language Problems
© 1998 by Dr. Thomas W. MacFarland -- All Rights Reserved
Instructions: Review the following program and see if you can
predict the outcome by completing a "pencil
trace" of the code.
Program output is provided at the end of this
page.
Compiler: The program was prepared using Standard Pascal
on a UNIX-based host computer.
% cat PASCAL/advanced_pencil-09.p
{ Advanced Pascal Programming Language Exercises
Dr. Thomas W. MacFarland
advanced_pencil-09.p
}
{ The purpose of this program is to:
1. Demonstrate the use of recursion to produce highly
compact code.
}
program Demonstrate_Recursion_2;
var Tally : real;
procedure Do_Something_Again(Z : real);
begin
Z := Z * 2.50;
writeln('Z = ',Z :9:4);
if Z <= 100 then
Do_Something_Again(Z);
writeln('Z = ',Z:9:4);
end; {end procedure Do_Something_Again}
begin (* main program *)
Tally := 1.5;
writeln('Tally = ',Tally:9:4);
writeln('******************');
Do_Something_Again(Tally);
end. {advanced_pencil-09.p}
% pc PASCAL/advanced_pencil-09.p
% a.out
Tally = 1.5000
******************
Z = 3.7500
Z = 9.3750
Z = 23.4375
Z = 58.5938
Z = 146.4844
Z = 146.4844
Z = 58.5938
Z = 23.4375
Z = 9.3750
Z = 3.7500