unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
Label2: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var m:int64;
Form1: TForm1;
implementation
{$R *.dfm}
function pruefen(n: int64): boolean;
var
x: int64;
p: boolean;
begin
p := true;
x := round(n / 2);
if n >= 2
then
begin
while x > 1
do
begin
if (n
mod x) = 0
then
begin
p := false;
break;
end;
x := x-1;
end;
end else
p := false;
if p = true
then
pruefen := true
else
pruefen := false;
end;
procedure zerlegen(n: int64);
var
x:int64;
begin
x:=2;
while (n
mod x <> 0)
do
x := x + 1;
if Length(form1.Label2.Caption) > 0
then
Form1.Label2.Caption := Form1.Label2.Caption + '
*';
Form1.Label2.Caption := Form1.Label2.Caption + IntTosSr(x);
if pruefen(n
div x) = false
then zerlegen(n
div x);
m := m * x;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
m := 1;
Label2.Caption := '
';
if pruefen(StrToInt(Edit1.Text)) = True
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.