Posted on Leave a comment

Compare natural numbers

Compare without if, case, <, >

[code language=”delphi”]
var
a, b: word;
a1, b1: word;
begin
a := abs(strtoint(Edit1.Text));
b := abs(strtoint(Edit2.Text));
a1 := a div b;
a1 := ((a1 + 2) div (a1 + 1)) mod 2;
b1 := (a1 + 1) mod 2;
Edit3.Text := inttostr(a*a1+b*b1) + ‘ >= ‘ + inttostr(a*b1+b*a1);
end;
[/code]

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.