Hej,
Prosiłbym o pomoc w znalezieniu błędu. Program ma przedstawiać liczbę w postaci iloczynu potęg liczb pierwszych. Ogólnie działa tak, że sprawdza wystąpienia dzielników do jego pierwiastka a jeśli ich nie ma to znaczy, że liczba jest liczą pierwszą. Program się kompiluje, ale po wpisaniu jakiejś liczby zawiesza.
unit z1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
i, j, k, a, e, temp: Integer;
tab: array of Integer;
napis: String;
pierwsza: Boolean;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
a:=strtoint(Edit1.Text);
e:=floor(sqrt(a))+1;
SetLength(tab, e);
temp:=a;
//Zerowanie tablicy
j:=0;
while j
begin
tab[i]:=0;
end;
//Tabelka wystąpień
i:=3;
if a=2 then tab[a]:=1
else
begin
while i<=e do
begin
if (a mod i) = 0 then
begin
tab[i]:=tab[i]+1;
a:=a div i;
end
else i:=i+2;
end;
end;
//Sprawdzanie czy jest pierwsza
pierwsza:=true;
i:=3;
while i<=e do
begin
if tab[i]<>0 then
begin
pierwsza:=false;
Break;
end;
end;
//Wyświetlanie
j:=2;
if pierwsza=true then napis:=IntToStr(temp)
else
begin
while j<=e do
begin
if (tab[j]>0) then
begin
if tab[j]=1 then napis:=napis+IntToStr(j)
else napis:=napis+IntToStr(j)+'^'+IntToStr(tab[j]);
if i<>e-1 then napis:=napis+'*';
end;
j:=j+1;
end;
end;
Edit2.Text:=napis;
end;
end.