一组数里面,比如有11个数,按顺序取出,比如每次取2个,怎么写啊?(50)

X

xf_z

Unregistered / Unconfirmed
GUEST, unregistred user!
一组数里面,比如有11个数,按顺序取出,比如每次取2个,怎么写啊?
 
Var ct:word=1;
//全局procedure get2no(var n1,n2:integer);label _done;
begin
n1:=-1;
n2:=-1;
if ct>11 then
begin
_done: 取完了! exit;
end;
inc(ct);
n1:=arr[ct];
inc(ct);
if ct>11 then
goto _done;
n1:=arr[ct];
end;
 
可以利用记录啊,比如说先定义一个有两个变量的记录。然后定义一个函数用来接收一个数组和它的长度,以及数组的下标,返回一个刚才建立的记录。如定义这样一个记录。Type TG2Rec = record int1 : integer;
int2 : integer;
end;
 
总数和取几个数是不确定的啊,我觉得应该是利用个双重循环吧?就是不确定怎么取得第N次是从哪个数开始取
 
procedure Get2Num(Anum:array of integer;var N1,N2:integer);var i,H,L:integer;
begin
H:=High(Anum);
L:=Low(Anum);
N1:=-1;
N2:=-1;
if C > H then
exit;
//C为全局变量 if C < L then
C:=L;
N1:=Anum[C];
inc(C);
if C > H then
exit;
N2:=Anum[C];
inc(C);
end;
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
961
SUNSTONE的Delphi笔记
S
顶部