-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpascal.pas
More file actions
67 lines (53 loc) · 1.21 KB
/
pascal.pas
File metadata and controls
67 lines (53 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
program SyntaxHighlighterTest;
{$APPTYPE CONSOLE}
{$MODE OBJFPC} // For Free Pascal compatibility
uses
SysUtils, Math;
const
PiApprox = 3.14159;
MaxItems = 100;
type
TPerson = record
Name: string;
Age: Integer;
procedure Print;
end;
TIntegerArray = array[1..MaxItems] of Integer;
TFunc = function(x: Double): Double;
var
i: Integer;
NameList: array[1..5] of string = ('Alice', 'Bob', 'Charlie', 'Dave', 'Eve');
Person: TPerson;
NumList: TIntegerArray;
Callback: TFunc;
procedure TPerson.Print;
begin
WriteLn('Name: ', Name);
WriteLn('Age: ', Age);
end;
function Square(x: Double): Double;
begin
Result := x * x;
end;
function Factorial(n: Integer): Integer;
begin
if n <= 1 then
Result := 1
else
Result := n * Factorial(n - 1);
end;
begin
Person.Name := 'John Doe';
Person.Age := 30;
Person.Print;
Callback := @Square;
WriteLn('Square of 5: ', Callback(5.0):0:2);
for i := 1 to 5 do
WriteLn('Name ', i, ': ', NameList[i]);
try
WriteLn('Factorial of 5 is: ', Factorial(5));
except
on E: Exception do
WriteLn('An error occurred: ', E.Message);
end;
end.