Code: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); function AnzahlWege(x,y,end_x,end_y:integer):integer; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin edit1.text:=inttoStr(anzahlwege(0,0,5,5)); end; function TForm1.AnzahlWege(x,y,end_x,end_y:integer):integer; var zahl:integer; begin if (x = end_x) and (y = end_y) then result:=1; // wenn nur 1x1 kästchen zahl:=0; if (x < end_x) then zahl := zahl + anzahlWege(x+1,y,end_x,end_y); if (y < end_y) then zahl := zahl + anzahlWege(x,y+1,end_x,end_y); result:=zahl; end; end. mein delphigeblubber. leider ist result immer 0. immer.
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; procedure Button1Click(Sender: TObject); function AnzahlWege(x,y,end_x,end_y:integer):integer; private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); begin edit1.text:=inttoStr(anzahlwege(0,0,5,5)); end; function TForm1.AnzahlWege(x,y,end_x,end_y:integer):integer; var zahl:integer; begin if (x = end_x) and (y = end_y) then result:=1; // wenn nur 1x1 kästchen zahl:=0; if (x < end_x) then zahl := zahl + anzahlWege(x+1,y,end_x,end_y); if (y < end_y) then zahl := zahl + anzahlWege(x,y+1,end_x,end_y); result:=zahl; end; end.
-- cats are not characteristically disposed toward voluntary aerobic exercise
Geändert von FF (22.03.2007 um 17:03 Uhr)
Foren-Regeln