- UID
- 55592
注册时间2008-9-3
阅读权限10
最后登录1970-1-1
周游历练
TA的每日心情 | 开心 2024-4-19 07:05 |
---|
签到天数: 8 天 [LV.3]偶尔看看II
|
- unit Unit1;
- inte**ce
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls;
- type
- TForm1 = class(TForm)
- btn1: TButton;
- mmo1: TMemo;
- procedure btn1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- function sum(const A:array of Integer): Integer;
- var
- I:Integer;
- begin
- for I := Low(A) to High(A) do
- Result := Result + A[I];
- end;
- procedure TForm1.btn1Click(Sender: TObject);
- var
- Summer1,Summer2:Integer;
- begin
- Summer1 := sum([1,2,3,4,5]);
- ShowMessage('数组1:sum[1,2,3,4,5]=' + IntToStr(Summer1));
- Summer2 := sum([1,2,3,4,5,6]);
- ShowMessage('数组2:sum[1,2,3,4,5,6]=' + IntToStr(Summer2));
- end;
- end.
复制代码 程序运行后,计算得Summer1 = 15,是正确的
而summer2=262169
这是怎么计算出来的呢? |
|