Jump to content

Floyd's triangle: Difference between revisions

(+ D entry)
(→‎{{header|Pascal}}: add example)
Line 195:
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105 </pre>
=={{header|Pascal}}==
{{works with|Free_Pascal}}
<lang pascal>Program FloydDemo (input, output);
 
procedure floyd (numberOfLines: integer);
 
var
i, j, digits, numbersInLine: integer;
 
begin
digits := trunc(ln(numberOfLines*(numberOfLines+1))/ln(10));
i := 1;
j := 1;
numbersInLine := 1;
repeat
repeat
write(i: digits+1, ' ');
inc(i);
inc(j);
until (j > numbersInLine);
writeln;
j := 1;
inc(numbersInLine);
until (numbersInLine > numberOfLines);
end;
 
begin
floyd(5);
floyd(14);
end.</lang>
Output:
<pre>% ./Floyd
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
56 57 58 59 60 61 62 63 64 65 66
67 68 69 70 71 72 73 74 75 76 77 78
79 80 81 82 83 84 85 86 87 88 89 90 91
92 93 94 95 96 97 98 99 100 101 102 103 104 105 </pre>
 
=={{header|Python}}==
<lang python>>>> def floyd(rowcount=5):
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.