Added Programs
- modified biketour with procedures - modified producttable with functions - modified squares with functionsdevelop
parent
fbfe1e89ef
commit
2725cdedbc
@ -0,0 +1,54 @@
|
||||
program big_array;
|
||||
|
||||
uses dateutils, sysutils;
|
||||
|
||||
type
|
||||
tup = record
|
||||
num : integer;
|
||||
sq : integer;
|
||||
end;
|
||||
|
||||
var
|
||||
a : array[0..10000] of tup;
|
||||
|
||||
procedure fill_array;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := 0 to 10000 do
|
||||
begin
|
||||
a[i].num := i;
|
||||
a[i].sq := i*i;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure do_something(arr: array of tup);
|
||||
begin
|
||||
arr[0].num := 1;
|
||||
end;
|
||||
|
||||
procedure do_something_ref(var arr: array of tup);
|
||||
begin
|
||||
arr[2].num := 1;
|
||||
end;
|
||||
|
||||
procedure measurement;
|
||||
var
|
||||
i : integer;
|
||||
time : TdateTime;
|
||||
begin
|
||||
time := Timeof(NOW);
|
||||
for i := 1 to 10000 do
|
||||
do_something(a);
|
||||
WriteLn('By Value', MilliSecondSpan(time, Timeof(now)):4);
|
||||
time := Timeof(NOW);
|
||||
for i := 1 to 10000 do
|
||||
do_something_ref(a);
|
||||
WriteLn('By Reference: ', MilliSecondSpan(time, Timeof(now)):4);
|
||||
end;
|
||||
|
||||
begin
|
||||
Writeln;
|
||||
fill_array;
|
||||
measurement;
|
||||
end.
|
@ -0,0 +1,34 @@
|
||||
program faculty;
|
||||
|
||||
function faculty_it(num: integer) : longint;
|
||||
var
|
||||
val: longint = 1;
|
||||
i: integer;
|
||||
|
||||
begin
|
||||
for i := 2 to num do
|
||||
begin
|
||||
val := val * i;
|
||||
end;
|
||||
faculty_it := val;
|
||||
end;
|
||||
|
||||
function faculty_rec(num: integer): longint;
|
||||
begin
|
||||
if num = 1 then
|
||||
faculty_rec := num
|
||||
else
|
||||
faculty_rec := num * faculty_rec(num-1);
|
||||
end;
|
||||
|
||||
var
|
||||
input : integer;
|
||||
|
||||
begin
|
||||
Writeln('Number: ');
|
||||
Read(input);
|
||||
Writeln;
|
||||
Writeln('Faculty IT: ', faculty_it(input));
|
||||
Writeln('Faculty REC: ', faculty_rec(input));
|
||||
|
||||
end.
|
@ -0,0 +1,22 @@
|
||||
program greater;
|
||||
|
||||
function greatest(num1, num2:integer) : integer;
|
||||
{ Returns the greater of two values. }
|
||||
begin
|
||||
if (num1 > num2) then
|
||||
greatest := num1
|
||||
else
|
||||
greatest := num2;
|
||||
end;
|
||||
|
||||
var
|
||||
num1, num2, ret : integer;
|
||||
|
||||
begin
|
||||
Writeln('Number 1: ');
|
||||
Read(num1);
|
||||
Writeln('Number 2: ');
|
||||
Read(num2);
|
||||
Writeln;
|
||||
Writeln(greatest(num1, num2));
|
||||
end.
|
@ -1,26 +1,40 @@
|
||||
program squares;
|
||||
|
||||
procedure squares_for;
|
||||
var
|
||||
i : integer;
|
||||
|
||||
begin;
|
||||
begin
|
||||
for i := 0 to 20 do
|
||||
Write(i*i, ' ');
|
||||
Writeln;
|
||||
end;
|
||||
|
||||
i := 0;
|
||||
procedure squares_while;
|
||||
var
|
||||
i : integer = 0;
|
||||
begin
|
||||
while i <= 20 do
|
||||
begin
|
||||
Write(i*i, ' ');
|
||||
i := i+1;
|
||||
end;
|
||||
Writeln;
|
||||
end;
|
||||
|
||||
i := 0;
|
||||
procedure squares_repeat;
|
||||
var
|
||||
i : integer = 0;
|
||||
begin
|
||||
repeat
|
||||
begin
|
||||
Write(i*i, ' ');
|
||||
i := i+1;
|
||||
end;
|
||||
until i > 20;
|
||||
end;
|
||||
|
||||
begin;
|
||||
squares_for;
|
||||
squares_while;
|
||||
squares_repeat;
|
||||
end.
|
Loading…
Reference in New Issue