mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-12 04:26:13 +02:00
Added High/liw/Ord/Pred/Succ
This commit is contained in:
parent
692155686a
commit
8b404b158d
@ -47,7 +47,7 @@ ex41.pp contains an example of the MemAvail function.
|
|||||||
ex42.pp contains an example of the Move function.
|
ex42.pp contains an example of the Move function.
|
||||||
ex43.pp contains an example of the Odd function.
|
ex43.pp contains an example of the Odd function.
|
||||||
ex44.pp contains an example of the Ofs function.
|
ex44.pp contains an example of the Ofs function.
|
||||||
ex45.pp contains an example of the Ord function.
|
ex45.pp contains an example of the Ord, Pred and Succ functions.
|
||||||
ex46.pp contains an example of the ParamCount and ParamStr functions.
|
ex46.pp contains an example of the ParamCount and ParamStr functions.
|
||||||
ex47.pp contains an example of the Pi function.
|
ex47.pp contains an example of the Pi function.
|
||||||
ex48.pp contains an example of the Pos function.
|
ex48.pp contains an example of the Pos function.
|
||||||
@ -82,3 +82,4 @@ ex76.pp contains an example of the FillWord function.
|
|||||||
ex77.pp contains an example of the Rename function.
|
ex77.pp contains an example of the Rename function.
|
||||||
ex78.pp contains an example of the Power function.
|
ex78.pp contains an example of the Power function.
|
||||||
ex79.pp contains an example of the SetJmp/LongJmp functions.
|
ex79.pp contains an example of the SetJmp/LongJmp functions.
|
||||||
|
ex80.pp contains an example of the High/Low functions.
|
@ -1,6 +1,6 @@
|
|||||||
Program Example45;
|
Program Example45;
|
||||||
|
|
||||||
{ Program to demonstrate the Ord function. }
|
{ Program to demonstrate the Ord,Pred,Succ functions. }
|
||||||
|
|
||||||
Type
|
Type
|
||||||
TEnum = (Zero, One, Two, Three, Four);
|
TEnum = (Zero, One, Two, Three, Four);
|
||||||
@ -11,7 +11,11 @@ Var
|
|||||||
|
|
||||||
begin
|
begin
|
||||||
X:=125;
|
X:=125;
|
||||||
Writeln (Ord(X)); { Prints 125 }
|
Writeln (Ord(X)); { Prints 125 }
|
||||||
|
X:=Pred(X);
|
||||||
|
Writeln (Ord(X)); { prints 124 }
|
||||||
Y:= One;
|
Y:= One;
|
||||||
Writeln (Ord(y)); { Prints 1 }
|
Writeln (Ord(y)); { Prints 1 }
|
||||||
|
Y:=Succ(Y);
|
||||||
|
Writeln (Ord(Y)); { Prints 2}
|
||||||
end.
|
end.
|
||||||
|
38
docs/refex/ex80.pp
Normal file
38
docs/refex/ex80.pp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
Program example80;
|
||||||
|
|
||||||
|
{ Example to demonstrate the High and Low functions. }
|
||||||
|
|
||||||
|
Type TEnum = ( North, East, South, West );
|
||||||
|
TRange = 14..55;
|
||||||
|
TArray = Array [2..10] of Longint;
|
||||||
|
|
||||||
|
Function Average (Row : Array of Longint) : Real;
|
||||||
|
|
||||||
|
Var I : longint;
|
||||||
|
Temp : Real;
|
||||||
|
|
||||||
|
|
||||||
|
begin
|
||||||
|
Temp := Row[0];
|
||||||
|
For I := 1 to High(Row) do
|
||||||
|
Temp := Temp + Row[i];
|
||||||
|
Average := Temp / (High(Row)+1);
|
||||||
|
end;
|
||||||
|
|
||||||
|
Var A : TEnum;
|
||||||
|
B : TRange;
|
||||||
|
C : TArray;
|
||||||
|
I : longint;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Writeln ('TEnum goes from : ',Ord(Low(TEnum)),' to ', Ord(high(TEnum)),'.');
|
||||||
|
Writeln ('A goes from : ',Ord(Low(A)),' to ', Ord(high(A)),'.');
|
||||||
|
Writeln ('TRange goes from : ',Ord(Low(TRange)),' to ', Ord(high(TRange)),'.');
|
||||||
|
Writeln ('B goes from : ',Ord(Low(B)),' to ', Ord(high(B)),'.');
|
||||||
|
Writeln ('TArray index goes from : ',Ord(Low(TArray)),' to ', Ord(high(TArray)),'.');
|
||||||
|
Writeln ('C index goes from : ',Low(C),' to ', high(C),'.');
|
||||||
|
For I:=Low(C) to High(C) do
|
||||||
|
C[i]:=I;
|
||||||
|
Writeln ('Average :',Average(c));
|
||||||
|
end.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user