⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.~pas

📁 用DEPHI实现计算最大公约数
💻 ~PAS
字号:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    Button1: TButton;
    function estate(s: string): String;
    procedure Button1Click(Sender: TObject);
    procedure Edit1KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Edit1KeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.estate(s: String): String;
var
  int1,i,j : Integer;
  sum,jc : variant;
  str1 : string;
begin
  sum := 3;
  int1 := StrToInt(s);
  jc := 2;
  if (int1<>1) and (int1<>2) then
  begin
  for i:=3 to int1 do
  begin
    jc:= jc*i;
    sum := sum+jc;
  end;
  str1 := sum;
  result := str1;
  end
  else
  begin
    if int1=1 then
      result := '1'
    else
      result := '2';
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit2.Text := estate(Trim(Edit1.Text));
end;

procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 { if key in [0..9] then
  begin
    if key>100 then
      Edit1.Text := '100';
  end;   }
end;

procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
  if key in [0..9] then
  begin
    if key>100 then
      Edit1.Text := '100';
  end;
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -