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:
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 := ''; Eingabe.Text := ''; Button2.Enabled := false; end;
end. |
Moderiert von
raziel: Delphi-Tags hinzugefügt