delphi 10.2 ----简单的递归函数例子求和
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.
總結
以上是生活随笔為你收集整理的delphi 10.2 ----简单的递归函数例子求和的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 为什么妃子笑是荔枝中的一个品种?
- 下一篇: 妃子笑为什么叫妃子笑?
