Skip to content

Instantly share code, notes, and snippets.

@simolus3
Last active October 13, 2016 12:35
Show Gist options
  • Save simolus3/2913d3ea64bd7351f76236392fea87b7 to your computer and use it in GitHub Desktop.
Save simolus3/2913d3ea64bd7351f76236392fea87b7 to your computer and use it in GitHub Desktop.
Rekursionsaufgaben
procedure TForm1.btnAddItClick(Sender: TObject);
var sum, i: integer;
begin
sum := 0;
for i := 1 to 4 do begin
sum := sum + (random(6) + 1);
end;
ShowMessage(IntToStr(sum));
end;
function TForm1.addiereXRec(x: integer): integer;
var rand: integer;
begin
rand := random(6) + 1;
if x > 1 then
addiereXRec := rand + addiereXRec(x - 1)
else
addiereXRec := rand;
end;
procedure TForm1.btnMaxItClick(Sender: TObject);
var max, rand, i: integer;
begin
max := 0;
for i := 1 to 4 do begin
rand := random(6) + 1;
if rand > max then
max := rand;
end;
ShowMessage(IntToStr(max));
end;
function TForm1.maxFinden(x: integer; max: integer): integer;
var rand: integer;
begin
rand := random(6) + 1;
if x = 0 then
exit(max);
if rand > max then
maxFinden := maxFinden(x - 1, rand)
else
maxFinden := maxFinden(x - 1, max);
end;
procedure TForm1.btnShowItClick(Sender: TObject);
var i: integer;
s: string;
begin
s := '';
for i := 1 to 4 do begin
s := IntToStr(random(6) + 1) + s;
end;
ShowMessage(s);
end;
function TForm1.gibXErgebnisse(x: integer): string;
var rand: integer;
begin
rand := random(6) + 1;
if x <= 1 then
gibXErgebnisse := IntToStr(rand)
else
gibXErgebnisse := IntToStr(rand) + gibXErgebnisse(x - 1);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment