Autor Beitrag
ConditionZero
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 190

Win XP
Delphi 7 PE, C++ (Dev-C++), HTML+PHP (Dreamweaver MX), JavaScript(MS FrontPage)
BeitragVerfasst: Fr 21.04.06 23:18 
Hi
Ich hab da ne kleine frage un zwar hab ich mich jetzt an einen prizahlgenerator rangemacht, der alle primzahlen von 2 bis zu einer bestimmten zahl ausgibt. da mir des ganze zeug mit arrays un so zu kompliziert ist *gg* habe ich ein memo fenster genommen als ausgabe der primzahlen und habe es mit module versucht das ging auch soweit ganz gut aber dann habe ich gesehen dass z.B. 3 mod 3 = 0 ist und dann 3 in der ausgabe nicht angezeigt wird. meine frage: wie kann ich denn die 3 trozdem anzeigen lassen (sollte nach möglichkeit in der richtigen reihenfolge sein die zahlen.) die primzahlen von 2-1000000 sollten aber in ca. 1 sek. ausgegeben sein.
Hier mein code:

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:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
procedure TForm1.Label3Click(Sender: TObject);
begin
close;         
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  Zahl: Integer;                     
  AktZahl: Integer;                    
i,TestZahl: Integer;                  
begin
Button2.Enabled := True;               
Zahl:= StrToInt (Eingabe.Text);       
AktZahl := 2;                         
  while AktZahl <= Zahl do           
  begin
  Ausgabe.Lines.Append (InttoStr (Aktzahl));  
  Aktzahl := AktZahl+1;                       
  end;
  for i:=ausgabe.lines.count-1 downto 0 do   
  begin
    TestZahl := StrToInt (ausgabe.lines [i]);   
    if (TestZahl mod 2)=0 then     
    begin
    ausgabe.lines.Delete(i);      
    end;
  end;

  for i:=ausgabe.lines.count-1 downto 0 do
  begin
    TestZahl := StrToInt (ausgabe.lines [i]);
    if (TestZahl mod 3)=0 then
    begin
    ausgabe.lines.Delete(i);
    end;
  end;

    for i:=ausgabe.lines.count-1 downto 0 do
  begin
    TestZahl := StrToInt (ausgabe.lines [i]);
    if (TestZahl mod 5)=0 then
    begin
    ausgabe.lines.Delete(i);
    end;
  end;

    for i:=ausgabe.lines.count-1 downto 0 do
  begin
    TestZahl := StrToInt (ausgabe.lines [i]);
    if (TestZahl mod 7)=0 then
    begin
    ausgabe.lines.Delete(i);
    end;
  end;

    for i:=ausgabe.lines.count-1 downto 0 do
  begin
    TestZahl := StrToInt (ausgabe.lines [i]);
    if (TestZahl mod 9)=0 then
    begin
    ausgabe.lines.Delete(i);
    end;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
Ausgabe.Text := '';   //Ausgabe wird geelert
Eingabe.Text := '';   //Eingabe wird geelert
Button2.Enabled := false;   //Leeren Button wird unbenutzbar
end;

end.


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Sa 22.04.06 20:04 
www.delphi-forum.de/...unktion_33013,0.html

Kannst dir ja diesen 13-Seiten-Thread mal durchlesen. Alles zum Thema "Primzahlen".

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)