давно
Старший Модератор
31795
6196
28.09.2021, 16:00
общий
это ответ
Доброе время суток!
Смотрите приложение:
[code lang=pascal h=400]unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Grids, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
procedure Button1Click(Sender: TObject);
procedure Edit1Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit2Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure FormCreate(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
Form1.StringGrid1.Cells[0,0]:='X';
Form1.StringGrid1.Cells[1,0]:='2^X-1';
Form1.StringGrid1.Cells[2,0]:='Status';
Form1.StringGrid1.RowCount:=2;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,c:longint;
function prime(a:longint):boolean;
var
b:integer;
begin
b:=a div 2;
while (b>1)and((a mod b)>0)do
dec(b);
prime:=b=1;
end;
begin
if TryStrToInt(Form1.Edit1.Text,a)and TryStrToInt(Form1.Edit2.Text,b)then
if(a>0)and(b>0)then
begin
if a>b then
begin
c:=a;
a:=b;
b:=c;
end;
Form1.StringGrid1.Cells[0,1]:=IntToStr(a);
c:=1;
while a>0do
begin
c:=c*2;
dec(a);
dec(b);
end;
Form1.StringGrid1.Cells[1,Form1.StringGrid1.RowCount-1]:=IntToStr(c-1);
if prime(c-1) then Form1.StringGrid1.Cells[2,Form1.StringGrid1.RowCount-1]:='True'
else Form1.StringGrid1.Cells[2,Form1.StringGrid1.RowCount-1]:='False';
for a:=1 to b do
begin
Form1.StringGrid1.RowCount:=Form1.StringGrid1.RowCount+1;
Form1.StringGrid1.Cells[0,Form1.StringGrid1.RowCount-1]:=IntToStr(StrToInt(Form1.StringGrid1.Cells[0,Form1.StringGrid1.RowCount-2])+1);
c:=c*2;
Form1.StringGrid1.Cells[1,Form1.StringGrid1.RowCount-1]:=IntToStr(c-1);
if prime(c-1) then Form1.StringGrid1.Cells[2,Form1.StringGrid1.RowCount-1]:='True'
else Form1.StringGrid1.Cells[2,Form1.StringGrid1.RowCount-1]:='False';
end;
end
else
ShowMessage('Please, enter correct data');
end;
procedure TForm1.Edit1Click(Sender: TObject);
begin
Form1.Edit1.Text:='';
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #13, #8]) then Key := #0;
end;
procedure TForm1.Edit2Click(Sender: TObject);
begin
Form1.Edit2.Text:='';
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if not (Key in ['0'..'9', #13, #8]) then Key := #0;
end;
end.[/code]
Удачи!
Об авторе:
Мне безразлично, что Вы думаете о обо мне, но я рад за Вас - Вы начали думать.