unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 =
class(TForm)
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
function pruefen(n: int64): boolean;
procedure zerlegen(n: Int64);
end;
var
m: int64;
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.pruefen(n: int64): boolean;
var
x: Int64;
begin
Result := True;
x := Round(n / 2);
if(n >= 2)
then
begin
while(x > 1)
do
begin
if((n
mod x) = 0)
then
begin
Result := False;
Break;
end;
Dec(x);
end;
end
else
Result := False;
end;
procedure TForm1.zerlegen(n: Int64);
var
x: int64;
begin
x := 2;
while((n
mod x) <> 0)
do
Inc(x);
if(Length(Label2.Caption) > 0)
then
Label2.Caption := Label2.Caption + '
*';
Label2.Caption := Label2.Caption + IntToStr(x);
if not(pruefen(n
div x))
then
zerlegen(n
div x);
m := m * x;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
m := 1;
Label2.Caption := '
';
if(pruefen(StrToInt(Edit1.Text)))
then
Label2.Caption := Edit1.Text + '
ist eine Primzahl!'
else
begin
zerlegen(StrToInt(Edit1.Text));
Label2.Caption := Label2.Caption + '
*' + IntToStr(StrToInt(Edit1.Text)
div m);
end;
end;
end.