Multiplication tables: Difference between revisions
Content added Content deleted
Underscore (talk | contribs) (→{{header|Perl}}: Removed more magic numbers. Removed shebang line and "use strict", since they're implied. Switched to the statement-modifier form of "foreach" where possible, for readability.) |
|||
Line 224: | Line 224: | ||
=={{header|Perl}}== |
=={{header|Perl}}== |
||
<lang perl> |
<lang perl>our $max = 12; |
||
our $width = length($max**2) + 1; |
|||
use strict; |
|||
our $max = 12; |
|||
printf "%${width}s", $_ foreach 'x|', 1..$max; |
|||
print " x|"; |
|||
⚫ | |||
foreach my $a (1..$max) { printf(" %3d", $a); } |
|||
⚫ | |||
foreach my $i (1..$max) { |
foreach my $i (1..$max) { |
||
printf |
printf "%${width}s", $_ |
||
foreach "$i|", map { $_ >= $i and $_*$i } 1..$max; |
|||
print "|"; |
|||
foreach my $j (1..$max) { |
|||
if ($j >= $i) { printf(" %3d", $j*$i); } |
|||
else { print " "; } |
|||
} |
|||
print "\n"; |
print "\n"; |
||
}</lang> |
}</lang> |
||
Output: |
Output: |
||
<pre> |
<pre> |
||
x| 1 2 3 4 5 6 7 8 9 10 11 12 |
x| 1 2 3 4 5 6 7 8 9 10 11 12 |