Thema: Primzahl

Einzelnen Beitrag anzeigen

Benutzerbild von Wolfgang Mix
Wolfgang Mix

Registriert seit: 13. Mai 2009
Ort: Lübeck
1.222 Beiträge
 
Delphi 2005 Personal
 
#22

AW: Primzahl

  Alt 18. Mai 2011, 11:26
zusammengefasst:


Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var n, teiler, zahl :integer;
    wurzel :real;
    prim :boolean;
begin
  ListBox1.clear;
  n:=strtoint(Edit1.text);
  ListBox1.items.Add('2');
  zahl:=3;

  while zahl<=n do
  begin
    prim:=true;
    teiler:=3;
    wurzel:=sqrt(zahl);
    while (teiler <= wurzel) and (prim) do
    begin
      if zahl mod teiler=0 then prim := false;
      inc(teiler,2) ;
    end;

  if prim then
    listbox1.Items.Add (inttostr(zahl));
  inc(zahl,2);

  end;
end;
Wolfgang Mix
if you can't explain it simply you don't understand it well enough - A. Einstein
Mein Baby:http://www.epubli.de/shop/buch/Grund...41818516/52824
  Mit Zitat antworten Zitat