Last active
October 13, 2016 12:35
-
-
Save simolus3/2913d3ea64bd7351f76236392fea87b7 to your computer and use it in GitHub Desktop.
Rekursionsaufgaben
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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