Autor Beitrag
Baltus
Hält's aus hier
Beiträge: 12

Win XP
Delphi 5
BeitragVerfasst: Mi 18.04.07 19:10 
Hallo zusammen,

ich möchte, dass der ggT zweier Zahlen in ein Label eingetragen wird. Klappt aber nicht so richtig.
Habt ihr vielleicht eine Idee?

ausblenden volle Höhe 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:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
unit mggT;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TggT = class(TForm)
    bt_rechnen: TButton;
    Edit1: TEdit;
    Edit2: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    function ggT (a,b:integer):integer;
    procedure bt_rechnenClick(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  ggT: TggT;

implementation

{$R *.DFM}

function TggT.ggT(a,b:integer):integer;
var rest : integer ;
begin
 while b <> 0 do
  begin
   rest := a mod b;
   a := b;
   b := rest;
  end;
   result := a;
end;

procedure TggT.bt_rechnenClick(Sender: TObject);
begin
 Label1.caption := ggT(IntToStr(Edit1.text),IntToStr(Edit2.text)); //Was muss hier hin?????
end;

end.


Danke schon mal im Vorraus
MfG
Karlson
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 2088



BeitragVerfasst: Mi 18.04.07 19:14 
Moin!

ausblenden Delphi-Quelltext
1:
Label1.caption := inttostr(ggT(strToInt(edit1.text), strToInt(edit2.text)));