Posted on

Compare natural numbers

Compare without if, case, <, >

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;
Leave a Reply

Your email address will not be published. Required fields are marked *

 

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