function fibit(n: Integer): Integer;
var
a, b, i, temp: Integer;
begin
temp := 1;
a := 1;
b := 1;
for i := 1 to n - 1 do
begin
temp := a + b;
a := b;
b := temp;
end;
Result := temp;
end;
function fibrec(n: Integer): Integer;
var
temp: Integer;
begin
temp := 0;
if (n = 0) then temp := 1;
if (n = 1) then temp := 1;
if (n > 1) then temp := fibrec(n - 1) + fibrec(n - 2);
Result := temp;
end;
Beispiel :
procedure TForm1.Button1Click(Sender: TObject);
var
a : Integer;
begin
a := StrToInt(Edit1.text);
Memo1.Lines.add(IntToStr(fibit(a)));
// ShowMessage(IntToStr(fibrec(10)));
end;
Keine Kommentare:
Kommentar veröffentlichen