Einzelnen Beitrag anzeigen

Fridolin Walther

Registriert seit: 11. Mai 2008
Ort: Kühlungsborn
446 Beiträge
 
Delphi 2009 Professional
 
#6

Re: fakultät ausrechnen - Exception wenn Wert zu groß wird

  Alt 24. Jun 2009, 21:56
Delphi-Quellcode:
function fakultaet_nonrecursive(UpperLimit: Int64) : Int64;
var
  i : Int64;
begin
  Result := 1;
  i := 2;
  while i <= UpperLimit do
    begin
      if Result * i < Result then
        raise Exception.Create('Integerüberlauf!');
      Result := Result * i;
      inc(i);
    end;
end;
Wäre mein Vorschlag. Ohne Fehlerhandling. Keine Rekursion. Wirft ne Exception sobald es überläuft. Übrigens wie mein Vorredner bereits gesagt hat bei 21.
Fridolin Walther
"While Mr. Kim, by virtue of youth and naiveté, has fallen prey to the inexplicable need for human contact, let me step in and assure you that my research will go on uninterrupted, and that social relationships will continue to baffle and repulse me."
  Mit Zitat antworten Zitat