Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://pastebin.com/CtXNxPXi
- var
- Form1: TForm1;
- iValue, iCode: Integer;
- index, anzahlgaeste: Integer;
- gaeste: array of string;
- zahl:array[1..1000] of boolean;
- i,j,grenze:integer;
- implementation
- {$R *.DFM}
- procedure TForm1.Button1Click(Sender: TObject);
- begin
- if n.text = '' then
- begin
- error.text := 'Feld ist leer';
- n.SetFocus;
- end
- else begin
- val(n.text, iValue, iCode);
- if iCode = 0 then
- begin
- if StrToInt(n.text) < 2 then
- begin
- error.text := 'Zahl ist kleiner als zwei';
- n.SetFocus;
- end
- else
- begin
- error.text := 'Erfolgreich';
- //SetLength(gaeste, StrToInt(n.text));
- //result.Caption := IntToStr(High(gaeste));
- //for index := 0 to StrToInt(n.text) do
- // begin
- // result.text := result.text + 'gaeste[index]';
- // end;
- //https://mathematikalpha.de/primzahlsieb-des- eratosthenes
- //result.text := IntToStr(sizeof(zahl));
- grenze:=1000;
- fillchar(zahl,sizeof(zahl),true);
- i:=2; //erste Streichzahl
- repeat
- j:=i+i;
- repeat
- zahl[j]:=false;
- j:=j+i; //nächste zu streichende Zahl
- until j>grenze;
- inc(i);
- while zahl[i]=false do inc(i);
- until i>sqrt(grenze);
- for i:=2 to grenze do
- //if zahl[i] then write(i:8);
- //BoolToStr(Value: Boolean): String;
- //result.text := BoolToStr(zahl[i]);
- end;
- end
- else
- begin
- error.text := 'Keine (natürliche) Zahl';
- n.SetFocus;
- end
- end;
- end;
- end.
Add Comment
Please, Sign In to add comment