Autor Beitrag
codex2001
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 23.06.05 17:31 
hallo! also schaut euch zuerst mal den quelltext hier an:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
procedure TForm1.Button8Click(Sender: TObject);
var a,b,c,d,e : integer;
begin
        a := StrToInt(Edit1.Text);
        b := StrToInt(Edit2.Text);
           if a < b then
                begin
                 for c := b  downto 0 do
                   if (c mod a = 0and (c mod b = 0then
                   begin
                   Label1.Caption := IntToStr(c);
                   break;
                   end
           else
                 if a > b then
                  begin
                   for d := b downto 1 do
                   if (d mod a = 0and (d mod b = 0then
                   begin
                  Label1.Caption := IntToStr (d);
                  break;
                   end
                   end
                end;

das programm lässt sich ganz normal starten, also er bringt keine fehlermeldung, aber er rechnet mit den ggT zweier zahlen einfach nicht aus! wisst ihr, was hier falsch ist?

bye

Moderiert von user profile iconChristian S.: Delphi-Tags hinzugefügt.


Zuletzt bearbeitet von codex2001 am Do 23.06.05 19:56, insgesamt 1-mal bearbeitet
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.06.05 18:10 
Moin und :welcome: im Forum!

Ich weiß zwar nicht so wirklich, was du da machen willst :gruebel:, aber falls das ein ggT-Algorithmus werden soll (größter gemeinsamer Teiler), dann schau dir doch mal das hier an.

cu
Narses
JayK
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 1013



BeitragVerfasst: Do 23.06.05 19:17 
gkT, kgT???
Kenn ich nicht :nixweiss:
Ich kenne nur kgV und ggT ;)
codex2001 Threadstarter
Hält's aus hier
Beiträge: 2



BeitragVerfasst: Do 23.06.05 19:56 
user profile iconJayK hat folgendes geschrieben:
gkT, kgT???
Kenn ich nicht :nixweiss:
Ich kenne nur kgV und ggT ;)


ja .... ich weiß auch nicht was ich wieder gedacht habe als ich das geschrieben hab :shock: !
ich meine natürlich ggT!

Zitat:

Moin und im Forum!

Ich weiß zwar nicht so wirklich, was du da machen willst , aber falls das ein ggT-Algorithmus werden soll (größter gemeinsamer Teiler), dann schau dir doch mal das hier an.

cu
Narses


ok thx... hab ich eben auch schon gelesen, aber ich würde gerne den fehler in meinem prog. wissen! das prog. ist ja etwas anders aufgebaut
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10183
Erhaltene Danke: 1256

W10ent
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 23.06.05 23:21 
Moin!

Wenn du´s so machst, geht´s: :wink:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
procedure TForm1.Button1Click(Sender: TObject);
  var
    a,b,c: Integer;
begin
  a := StrToInt(Edit1.Text);
  b := StrToInt(Edit2.Text);
  if (b < a) then begin
    c := a;
    a := b;
    b := c;
  end;
  c := b;
  while (((a mod c) <> 0or ((b mod c) <> 0)) do
    Dec(c);
  Label1.Caption := IntToStr(c);
end;


Was hast du "falsch" gemacht:
- zu umständlich progammiert :wink:
- du hast die mod-Argumente vertauscht
- du hast eine begin-end-Klammer zuviel in der äußeren if-Anweisung

cu
Narses
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Mo 01.08.05 22:20 
Auch wenn's ein Delphi-Forum ist - so was hab ich mal in Assembler gemacht: :wink:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
{$APPTYPE CONSOLE}
program TestGCD;

// Greatest Common Divisor
function GCD(a, b: LongWord): LongWord; assembler;
asm
  MOV EAX, a    // a => EAX
  MOV EBX, b    // b => EBX
  CMP EBX, EAX  // EBX > EAX ?
  JB @@Again
  XCHG EAX, EBX // EAX <=> EBX
@@Again:
  OR EBX, EBX   // EBX = 0 ?
  JZ @@OK
  XOR EDX, EDX  // EDX := 0
  DIV EBX       // EDX:EAX / EBX => EAX\EDX
  MOV EAX, EBX  // EBX => EAX
  MOV EBX, EDX  // EDX => EBX
  JMP @@Again
@@OK:           
  PUSH EAX
  POP AX        // EAX => DX:AX
  POP DX        // Result := DX:AX
end;

begin
  WriteLn(GCD(18363119031134903170)) // worst case: two consecutive huge Fibonacci numbers
end.


Mal so als "Begrüßungs-Contribution". 8) Die SWAG kennt ja heute kaum noch jemand.
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 03.08.05 13:27 
1. Das EBX-Register ist unter Delphi tabu.
2. Du vermischst 16-bit und 32-bit-Assembler.
3. Das Result (DWORD) wird vollständig über EAX zurückgegeben.

Die Register-Reihenfolge ist EAX, EDX, ECX, Stack. A (EAX) und B (EDX) sind bereits in den Registern enthalten.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
LigH
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 239

Win98SE, Win2000SP4
D7
BeitragVerfasst: Mi 03.08.05 13:36 
Sorry - war damals für Turbo-Pascal. Schon sicher >10 Jahre alt...

user profile iconBenBE hat folgendes geschrieben:
1. Das EBX-Register ist unter Delphi tabu.

Okay, dann PUSH/POP - sollte reichen, oder?

user profile iconBenBE hat folgendes geschrieben:
2. Du vermischst 16-bit und 32-bit-Assembler.

Dazu wären weitere Details nett.

user profile iconBenBE hat folgendes geschrieben:
3. Das Result (DWORD) wird vollständig über EAX zurückgegeben.
...
A (EAX) und B (EDX) sind bereits in den Registern enthalten.

:oops: Siehe oben. Seit Delphi 2 sollte das wohl so klappen, richtig?