标签:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
unit SumPlus;
interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm5 = class(TForm) lbl1: TLabel; edt1: TEdit; lbl2: TLabel; edt2: TEdit; lbl3: TLabel; edt3: TEdit; btn1: TButton; procedure btn1Click(Sender: TObject); private function GetSum(A: Integer) : Integer; //获取从0到A之间所有整数和 function GetSumPlus(A: Integer; B: Integer): Integer; { Private declarations } public { Public declarations } end; var Form5: TForm5; implementation {$R *.dfm} procedure TForm5.btn1Click(Sender: TObject); var x: Integer; y: Integer; z : Integer; begin x := StrToInt(edt1.text); y := StrToInt(edt2.Text); //z := StrToInt(edt3.Text); z:= GetSumPlus(x, y); //调用SumPlus函数 edt3.Text := IntToStr(z); end; function TForm5.GetSum(A: Integer) : Integer; //获取0到A之间所有整数和 var i : Integer; sum : Integer; begin sum := 0; for i := 0 to A do sum := sum + i; result := sum; end; function TForm5.GetSumPlus(A: Integer; B: Integer) : Integer; begin Result := GetSum(A) + GetSum(B) ; //嵌套调用函数 end; end. |
标签:
原文地址:http://www.cnblogs.com/kivin/p/4646964.html