Jump to content

Floyd's triangle: Difference between revisions

→‎{{header|Pascal}}: add variant with for loop
(→‎{{header|Pascal}}: add example)
(→‎{{header|Pascal}}: add variant with for loop)
Line 199:
<lang pascal>Program FloydDemo (input, output);
 
procedure floydfloyd1 (numberOfLines: integer);
{ variant with repeat .. until loop }
 
var
i, j, digits, numbersInLine: integer;
 
begin
digits := trunc(ln(numberOfLines*(numberOfLines+1))/ln(10)) + 1;
i := 1;
j := 1;
Line 211:
repeat
repeat
write(i: digits+1, ' ');
inc(i);
inc(j);
Line 219:
inc(numbersInLine);
until (numbersInLine > numberOfLines);
end;
 
procedure floyd2 (numberOfLines: integer);
{ Variant with for .. do loop }
var
i, j, digits, numbersInLine: integer;
 
begin
digits := trunc(ln(numberOfLines*(numberOfLines+1))/ln(10)) + 1;
i := 1;
for numbersInLine := 1 to numberOfLines do
begin
for j := 1 to numbersInLine do
begin
write(i: digits, ' ');
inc(i);
end;
writeln;
end;
end;
 
begin
floydfloyd1(5);
floydfloyd2(14);
end.</lang>
Output:
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.