Autor Beitrag
bruce185
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Mi 01.02.06 13:50 
hi,
also ich bin gerade dabei ein kleines Rechenprogramm zu schreiben, und wenn ich 2 Zufallszahlen erzeuge und die erste grösser ist als der zweite z.B. so 50 - 70 dann möchte ich die Vertauschen 70 - 50 habe es so versucht:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Zahl1 = Zahl2;
  Zahl2 = Zahl1;

  Label1->Caption = IntToStr(Zahl1) + " - " + IntToStr(Zahl2);
}


aber dann sieht es so aus 70 - 70 wie mache ich das jetzt mit dem vertauschen?, ich danke euch schonmal für die hilfe :?

gruss andreas

Moderiert von user profile iconChristian S.: C#-Tags hinzugefügt
Chryzler
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1097
Erhaltene Danke: 2



BeitragVerfasst: Mi 01.02.06 13:58 
Wie wär's mit dem hier?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
var
Zahl1, Zahl2, tmp: Integer;
begin
tmp := Zahl1;
Zahl1 := Zahl2;
Zahl2 := tmp;
end;
AXMD
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 4006
Erhaltene Danke: 7

Windows 10 64 bit
C# (Visual Studio 2019 Express)
BeitragVerfasst: Mi 01.02.06 14:07 
@bruce185: Möchtest du eine Lösung in C# oder in Delphi? Falls ersteres zutrifft, müsste ich das Topic in die entsprechende Sparte verschieben.

AXMD
LLCoolDave
ontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic star
Beiträge: 212

Win XP
Delphi 2005
BeitragVerfasst: Mi 01.02.06 17:51 
Nur als kleine Anmerkung: Bei Zahlen braucht man keine zusätzliche Temp variable, es geht theoretisch auch so:

ausblenden Delphi-Quelltext
1:
2:
3:
a:=a+b;
b:=a-b;
a:=a-b;