✔ 最佳答案
Version 1: for - to - do loop
program WritePattern(input, output);
var
s : string[255];
i : integer;
begin
Write('Enter a word? ');
ReadLn(s);
WriteLn;
for i := 1 to Length(s) do
WriteLn(Copy(s, 1, Length(s) + 1 - i))
end.
— 或 —
program WritePattern(input, output);
var
s : string[255];
i : integer;
begin
Write('Enter a word? ');
ReadLn(s);
WriteLn;
for i := Length(s) downto 1 do
WriteLn(Copy(s, 1, i))
end.
Version 2: repeat - until loop
program WritePattern(input, output);
var
s : string[255];
i : integer;
begin
Write('Enter a word? ');
ReadLn(s);
WriteLn;
i := Length(s);
repeat
WriteLn(Copy(s, 1, i));
i := i - 1
until i < 1
end.
Version 3: while - do loop
program WritePattern(input, output);
var
s : string[255];
i : integer;
begin
Write('Enter a word? ');
ReadLn(s);
i := Length(s);
while i > 0 do
begin
WriteLn(Copy(s, 1, i));
i := i - 1
end
end.