Turbo Pascal 2.0Version of implementation Turbo Pascal of programming language Pascal
Turbo Pascal 2.0 was the second version of Turbo Pascal series, released on April 17, 1984.
Turbo Pascal 2.0 is much the same as Turbo Pascal 1.0, with slightly changed interface (gray-and-white palette instead of yellow-and-gray, removed “Execute” menu command etc.), a few minor compiler changes (like increase of generated executables size) and more examples.
Turbo Pascal 2.0: main menu
program helloworld; begin writeln('Hello, World!'); end.
This example is exactly the same as main recursive example for Pascal implementations, except for that it uses
real data type to store factorial values. Command
writeln(f:-1:0) outputs the floating point number
f with 0 digits after decimal point and left-justifies it.
program factorial; function fact(n: integer): real; begin if (n = 0) then fact := 1 else fact := n * fact(n - 1); end; var n: integer; begin for n := 0 to 16 do writeln(n, '! = ', fact(n):-1:0); end.
This example uses recursive definition of Fibonacci numbers.
program fibonacci; function fib(n:integer): integer; begin if (n <= 2) then fib := 1 else fib := fib(n-1) + fib(n-2); end; var i:integer; begin for i := 1 to 16 do write(fib(i), ', '); writeln('...'); end.
Pascal has built-in complex data type
complex, but using it is inconvenient in this case, because
writeln can’t output complex numbers directly, and functions
Im would have to be used. In this example calculations are done in real numbers. Library function
halt (added in Extended Pascal) exits current block (in later versions it is replaced with
program Quadratic; var A,B,C,D: integer; begin write('A = '); readln(A); if (A=0) then begin writeln('Not a quadratic equation.'); halt; end; write('B = '); readln(B); write('C = '); readln(C); D := B*B-4*A*C; if (D=0) then begin writeln('x = ',-B/2.0/A); halt; end; if (D>0) then begin writeln('x1 = ',(-B+Sqrt(D))/2.0/A); writeln('x2 = ',(-B-Sqrt(D))/2.0/A); end else begin writeln('x1 = (',-B/2.0/A,',',Sqrt(-D)/2.0/A,')'); writeln('x2 = (',-B/2.0/A,',',-Sqrt(-D)/2.0/A,')'); end; end.