Registriert seit: 25. Feb 2003
Ort: St. Ingbert
211 Beiträge
Delphi 7 Enterprise
|
Re: Fibonacci-Zahlen (iterativ)
29. Nov 2003, 21:21
Zitat von Kamil:
Bei der Fuktion Fehlt ein Ergebnis (result:=x)
Entweder so:
Delphi-Quellcode:
procedure TForm1.fibonit(n:integer);
var
x,y,z,i:integer;
begin
x:=1;
y:=1;
listbox1.items.add(inttostr(x));
listbox1.items.add(inttostr(y));
i:=0;
repeat
i:=i+1;
z:=x+y;
listbox1.items.add(inttostr(z));
y:=x;
x:=z;
until i=(n-1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
n: integer;
begin
n:=strtoint(edit1.text);
fibonit(n);
end;
oder so:
Delphi-Quellcode:
function TForm1.fibonit(n:integer): integer;
var
x,y,z,i:integer;
begin
x:=1;
y:=1;
i:=0;
repeat
i:=i+1;
z:=x+y;
y:=x;
x:=z;
until i=(n-1);
result:=z;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
n: integer;
begin
n:=strtoint(edit1.text);
listbox1.items.add(inttostr(fibonit(n)));
end;
Wozu? Warum nich gleich y := z; ?
Programming today is a race between Software Engineers striving to build bigger and better idiot-proof Programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning!
|