Guest User

Untitled

a guest
May 27th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. https://pastebin.com/CtXNxPXi
  2.  
  3. var
  4. Form1: TForm1;
  5. iValue, iCode: Integer;
  6. index, anzahlgaeste: Integer;
  7. gaeste: array of string;
  8. zahl:array[1..1000] of boolean;
  9. i,j,grenze:integer;
  10.  
  11. implementation
  12.  
  13. {$R *.DFM}
  14.  
  15. procedure TForm1.Button1Click(Sender: TObject);
  16. begin
  17. if n.text = '' then
  18. begin
  19. error.text := 'Feld ist leer';
  20. n.SetFocus;
  21. end
  22. else begin
  23. val(n.text, iValue, iCode);
  24. if iCode = 0 then
  25. begin
  26. if StrToInt(n.text) < 2 then
  27. begin
  28. error.text := 'Zahl ist kleiner als zwei';
  29. n.SetFocus;
  30. end
  31. else
  32. begin
  33. error.text := 'Erfolgreich';
  34. //SetLength(gaeste, StrToInt(n.text));
  35. //result.Caption := IntToStr(High(gaeste));
  36. //for index := 0 to StrToInt(n.text) do
  37. // begin
  38. // result.text := result.text + 'gaeste[index]';
  39. // end;
  40. //https://mathematikalpha.de/primzahlsieb-des- eratosthenes
  41. //result.text := IntToStr(sizeof(zahl));
  42. grenze:=1000;
  43. fillchar(zahl,sizeof(zahl),true);
  44. i:=2; //erste Streichzahl
  45. repeat
  46. j:=i+i;
  47. repeat
  48. zahl[j]:=false;
  49. j:=j+i; //nächste zu streichende Zahl
  50. until j>grenze;
  51. inc(i);
  52. while zahl[i]=false do inc(i);
  53. until i>sqrt(grenze);
  54. for i:=2 to grenze do
  55. //if zahl[i] then write(i:8);
  56. //BoolToStr(Value: Boolean): String;
  57. //result.text := BoolToStr(zahl[i]);
  58. end;
  59. end
  60. else
  61. begin
  62. error.text := 'Keine (natürliche) Zahl';
  63. n.SetFocus;
  64. end
  65. end;
  66.  
  67. end;
  68.  
  69. end.
Add Comment
Please, Sign In to add comment