PDA

View Full Version : Even(i:extended):boolean;



rotflmfwao
08-03-2007, 12:51 AM
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
08-03-2007, 01:42 AM
wayyy simpler way function even(i:integer):boolean;
begin
result:=(i mod 2 = 0);
end;

bullzeye95
08-03-2007, 02:01 AM
Why did you make it use extended variables?

Wikety Wikety Woah!
08-03-2007, 02:04 AM
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
08-05-2007, 10:46 PM
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