unit Unit10;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm10 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Edit5: TEdit;
Label5: TLabel;
Button1: TButton;
function sum1(A:integer):integer;
function xj(X,Y: integer):integer;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form10: TForm10;
implementation
{$R *.dfm}
{ TForm10 }
procedure TForm10.Button1Click(Sender: TObject);
begin
if (Edit1.Text='') and (Edit3.Text='') then
begin
showmessage('请输入数字');
EXIT; //退出message
end;
Edit2.Text:=intToStr(sum1(Strtoint((Edit1.Text))));
Edit4.Text:=intToStr(sum1(Strtoint((Edit3.Text))));
Edit5.Text:=IntToStr(xj(StrToint(Edit1.Text),StrToInt(Edit3.Text)));
end;
function TForm10.sum1(A: integer): integer; //求和函数
var
i,sum1:integer; //定义变量, i ,sum1
begin
sum1:=0;
for i := 0 to A do
sum1:=sum1+i;
result:=sum1;
end;
function TForm10.xj(X, Y: integer): integer; //减法函数
begin
result:=sum1(x)-sum1(y);
end;
end.