Introduction to the Pascal Programming Language
© 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/intro_pencil-03.p
{ Introduction to the Pascal Programming Language
Dr. Thomas W. MacFarland
intro_pencil-03.p
}
{ The purpose of this program is to:
1. Demonstrate mathematical operations using integer variables.
2. Demonstrate mathematical operations using real variables.
3. Demonstrate the use of ( and ) for control of the order of
mathematical operation.
}
program Demonstrate_Math_1;
var A, B : integer;
C, D : real;
begin
A := 19;
B := (A + (A * 3)) * (A - (6 + 893));
C := 19.98;
D := ((C * C) - B) / (C + (A + 2.32));
write(' A = ', A:8);
write(' B = ', B:8);
write(' C = ', C:8:3);
write(' D = ', D:8:3); writeln;
end. { intro_pencil-03.p }
% pc PASCAL/intro_pencil-03.p
% a.out
A = 19 B = -66880 C = 19.980 D = 1629.036