SRL Archive - Research & Development Lounge

Even(i:extended):boolean;


rotflmfwao

2007-08-02 20:51:45

Ugh, I searched all over for a function that tells you whether or not the number you input is even or odd. I eventualy made my own because I got tired of searching. Here it is:

Const i=10
Function Even(i:Extended):Boolean;
Var q,r:Extended;
Begin
r:=(i/2);
q:=Trunc(r);
If(SameValue(r,q))Then
Begin
Result:=True;
Exit;
End;
Result:=False;
End;

begin
ClearDebug;
If(Even(i))Then
Writeln('It is even');
If(Not(Even(i)))Then
Writeln('It''s not even');
end.
just put your # in i.

jhildy

2007-08-02 21:42:32

wayyy simpler way
function even(i:integer):boolean;
begin
result:=(i mod 2 = 0);
end;

bullzeye95

2007-08-02 22:01:20

Why did you make it use extended variables?

Wikety Wikety Woah!

2007-08-02 22:04:24

Ha-ha, I hadn't thought of math, or mod(which technically is still math). I would have made a case with 0-9 trying to find out if the last mr was even or odd :). Good job.

rotflmfwao

2007-08-05 18:46:50

Ugh, i totaly forgot about mod :( Btw, I used extended because to truncate a number, it needs to be extended.
EX:
4.72 Truncated or Trunc(4.72) = 4