Código
(* * * * * * * * * * * * * * * * * * * * * * * * * *) (* Function : IsPerfectNumber *) (* Author : *PsYkE1* *) (* Mail : vbpsyke1@mixmail.com *) (* Date : 24/8/10 *) (* Purpose : Check if number is a perfect number *) (* Visit : http://foro.rthacker.net/ *) (* * * * * * * * * * * * * * * * * * * * * * * * * *) function IsPerfectNumber(lNumber:Integer):Boolean; var i : Integer; x : Integer; begin I := 0; Result := false; if lnumber > 0 then begin for x := 1 to lnumber - 1 do begin if (lnumber mod x) = 0 then i := i + x; end; if i = lnumber then Result := true; end; end;
Ejemplo:
Código
procedure TForm1.FormCreate(Sender: TObject); var n:integer; s:String; begin n := 6; str(n,s); if IsPerfectNumber(n) = true then edit1.Text:= 'El ' + s + ' es un numero perfecto'; end; end.
DoEvents¡!