Advertisement
Guest User

Untitled

a guest
May 27th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7. StdCtrls;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. title: TLabel;
  12. Label1: TLabel;
  13. n: TEdit;
  14. sign: TLabel;
  15. Button1: TButton;
  16. error: TEdit;
  17. result: TEdit;
  18. procedure Button1Click(Sender: TObject);
  19. private
  20. { Private-Deklarationen }
  21. public
  22. { Public-Deklarationen }
  23. end;
  24.  
  25. var
  26. Form1: TForm1;
  27. iValue, iCode: Integer;
  28. index, anzahlgaeste: Integer;
  29. gaeste: array of string;
  30. zahl:array[1..1000] of boolean;
  31. i,j,grenze:integer;
  32.  
  33. implementation
  34.  
  35. {$R *.DFM}
  36.  
  37. procedure TForm1.Button1Click(Sender: TObject);
  38. begin
  39. if n.text = '' then
  40. begin
  41. error.text := 'Feld ist leer';
  42. n.SetFocus;
  43. end
  44. else begin
  45. val(n.text, iValue, iCode);
  46. if iCode = 0 then
  47. begin
  48. if StrToInt(n.text) < 2 then
  49. begin
  50. error.text := 'Zahl ist kleiner als zwei';
  51. n.SetFocus;
  52. end
  53. else
  54. begin
  55. error.text := 'Erfolgreich';
  56. SetLength(gaeste, StrToInt(n.text));
  57. //result.Caption := IntToStr(High(gaeste));
  58. //for index := 0 to StrToInt(n.text) do
  59. // begin
  60. // result.text := result.text + 'gaeste[index]';
  61. // end;
  62. //https://mathematikalpha.de/primzahlsieb-des-eratosthenes
  63. //result.text := IntToStr(sizeof(zahl));
  64. grenze:=1000;
  65. fillchar(zahl,sizeof(zahl),true);
  66. i:=2; //erste Streichzahl
  67. repeat
  68. j:=i+i;
  69. repeat
  70. zahl[j]:=false;
  71. j:=j+i; //nächste zu streichende Zahl
  72. until j>grenze;
  73. inc(i);
  74. while zahl[i]=false do inc(i);
  75. until i>sqrt(grenze);
  76. for i:=2 to grenze do
  77. if zahl[i] then write(i:8);
  78. end;
  79. end
  80. else
  81. begin
  82. error.text := 'Keine (natürliche) Zahl';
  83. n.SetFocus;
  84. end
  85. end;
  86.  
  87. end;
  88.  
  89. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement