Ένα πρόγραμμα το οποίο τυπώνει "Hello, World!".
- Κώδικας:
program hello_world;
begin
writeln('Hello, World!');
end.
program hello_world;
begin
writeln('Hello, World!');
end.
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.
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.
1. Program Calculate;
2. Var
3. Num1, Num2, Sum : Integer;
4.
5. Begin
6. Write('Input number 1:');
7. Readln(Num1);
8. Writeln('Input number 2:');
9. Readln(Num2);
10. Sum := Num1 + Num2;
11. Writeln(Sum);
12. End.
program Pressures ;
CONST
MAXREAL = 1.0E37 ;
type
pressuretype = array [1 .. 1000] of real ;
Procedure GetPressures (var n : integer ; var pressure : pressuretype) ;
begin
n := 1 ;
writeln ('ENTER A NEGATIVE PRESSURE TO TERMINATE DATA INPUT.') ;
writeln ;
while TRUE do begin
write ('ENTER PRESSURE #', n:0, ' ') ;
readln (pressure[n]) ;
if pressure[n] < 0.0 then begin
n := n - 1 ;
exit
end ;
n := n + 1
end
end ;
procedure ProcessPressures (n : integer ;
pressure : pressuretype ;
var
high, low, average : real) ;
var
total : real ;
count : integer ;
begin
total := 0.0 ;
count := 0 ;
high := pressure[1] ;
low := pressure[1] ;
for count := 1 to n do begin
total := total + pressure[count] ;
if pressure[count] > high then
high := pressure[count] ;
if pressure[count] < low then
low := pressure[count]
end ;
average := total / count
end ;
procedure PrintSummaryResults (n : integer ;
pressure : pressuretype ;
high, low, average : real) ;
var
i : integer ;
begin
writeln('NUMBER OF INTERVALS TO MONITOR: ', n) ;
writeln('**********************************') ;
for i := 1 to n do
writeln('PROCESS ', i:0, ' PRESSURE: ', pressure[i]:10:3);
writeln ;
if high > 5000.0 then
writeln('DANGER! OVERPRESSURE OF ', high:0:3) ;
if low < 14.0 then
writeln('DANGER! VACUUM OF ', low:0:3) ;
writeln('HIGH PRESSURE IS ', high:0:3) ;
writeln('LOW PRESSURE IS ', low:0:3) ;
writeln('AVERAGE PRESSURE IS ', average:0:3) ;
writeln('************************************')
end;
var
n : integer ;
pressure : pressuretype ;
high,
low,
average : real ;
begin
GetPressures (n, pressure) ;
ProcessPressures (n, pressure, high, low, average);
PrintSummaryResults (n, pressure, high, low, average);
end.