一道典型的编程题:将两个有序数组合并到有序第三个数组中,我用C语言中编写没有问题
但是将其给位delphi语言类型是就不对了,哪位delphi高手看看,修改下,谢谢。programee;{$APPTYPECONSOLE}typeTarr1=array[...
但是将其给位delphi语言类型是就不对了,哪位delphi高手看看,修改下,谢谢。
program ee;
{$APPTYPE CONSOLE}
type
Tarr1=array[1..5] of integer;
Tarr2=array[1..10] of integer;
var
a:Tarr1=(1,2,3,4,11);
b:Tarr1=(6,7,8,9,10);
c:Tarr2;
i,j,k:integer;
begin
i:=1;k:=1;j:=1;
while((i<=5) and (k<=5) and (j<=10)) do
begin
if(a[i]<=b[k]) then
begin
inc(i);
inc(j);
c[j]:=a[i];
end
else
begin
inc(k);
inc(j);
c[j]:=b[k];
end
end;
while((i<=5)and(j<=10)) do
begin
inc(i);
inc(j);
c[j]:=a[i];
end;
while((k<=5)and(j<=10)) do
begin
inc(k);
inc(j);
c[j]:=b[k];
end;
for j:=1 to 10 do
write(c[j],'---');
readln;
end. 展开
program ee;
{$APPTYPE CONSOLE}
type
Tarr1=array[1..5] of integer;
Tarr2=array[1..10] of integer;
var
a:Tarr1=(1,2,3,4,11);
b:Tarr1=(6,7,8,9,10);
c:Tarr2;
i,j,k:integer;
begin
i:=1;k:=1;j:=1;
while((i<=5) and (k<=5) and (j<=10)) do
begin
if(a[i]<=b[k]) then
begin
inc(i);
inc(j);
c[j]:=a[i];
end
else
begin
inc(k);
inc(j);
c[j]:=b[k];
end
end;
while((i<=5)and(j<=10)) do
begin
inc(i);
inc(j);
c[j]:=a[i];
end;
while((k<=5)and(j<=10)) do
begin
inc(k);
inc(j);
c[j]:=b[k];
end;
for j:=1 to 10 do
write(c[j],'---');
readln;
end. 展开
1个回答
展开全部
program ee;
{$APPTYPE CONSOLE}
type
Tarr1=array[1..5] of integer;
Tarr2=array[1..10] of integer;
const
a:Tarr1=(1,2,3,4,11); //定义常量数组
b:Tarr1=(6,7,8,9,10);
var
c:Tarr2;
i,j,k:integer;
begin
i:=1;k:=1;j:=1;
while((i<=5) and (k<=5)) do // j 不需再行判断
begin
if(a[i]<=b[k]) then
begin
c[j]:=a[i];
inc(i);
inc(j);
end
else
begin
c[j]:=b[k];
inc(k);
inc(j);
end
end;
while(i<=5) do // j 不需再行判断
begin
c[j]:=a[i];
inc(i);
inc(j);
end;
while(k<=5) do // j 不需再行判断
begin
c[j]:=b[k];
inc(k);
inc(j);
end;
for j:=1 to 10 do
write(c[j],'---');
readln;
end.
{$APPTYPE CONSOLE}
type
Tarr1=array[1..5] of integer;
Tarr2=array[1..10] of integer;
const
a:Tarr1=(1,2,3,4,11); //定义常量数组
b:Tarr1=(6,7,8,9,10);
var
c:Tarr2;
i,j,k:integer;
begin
i:=1;k:=1;j:=1;
while((i<=5) and (k<=5)) do // j 不需再行判断
begin
if(a[i]<=b[k]) then
begin
c[j]:=a[i];
inc(i);
inc(j);
end
else
begin
c[j]:=b[k];
inc(k);
inc(j);
end
end;
while(i<=5) do // j 不需再行判断
begin
c[j]:=a[i];
inc(i);
inc(j);
end;
while(k<=5) do // j 不需再行判断
begin
c[j]:=b[k];
inc(k);
inc(j);
end;
for j:=1 to 10 do
write(c[j],'---');
readln;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询