Multiplication tables: Difference between revisions
Content added Content deleted
(+Icon+Unicon) |
|||
Line 916: | Line 916: | ||
ENDDO |
ENDDO |
||
ENDDO</lang> |
ENDDO</lang> |
||
== Icon and Unicon == |
|||
==={{header|Icon}}=== |
|||
<lang Icon>procedure main() |
|||
lim := 13 |
|||
wid := 5 |
|||
every writes(right("* |" | (1 to lim) | "\n",wid)|right("\n",wid*(lim+1),"_")) # header rows |
|||
every (i := 1 to lim) & |
|||
writes(right( i||" |" | (j := 1 to lim, (if j < i then "" else i*j)\1) | "\n",wid)) # content |
|||
end </lang> |
|||
The above example is a somewhat exaggerated example of contractions. In both cases 'every' is used to force all alternatives including row labels, column headings, content, line terminators. The upper triangle is produced by embedding an 'if' expression inside the object of an 'every' (normally an error prone construct which would malfunction if not for the operator limiting generation to a single result (i.e. via expr \ 1). |
|||
Sample output:<pre> * | 1 2 3 4 5 6 7 8 9 10 11 12 13 |
|||
_____________________________________________________________________ |
|||
1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 |
|||
2 | 4 6 8 10 12 14 16 18 20 22 24 26 |
|||
3 | 9 12 15 18 21 24 27 30 33 36 39 |
|||
4 | 16 20 24 28 32 36 40 44 48 52 |
|||
5 | 25 30 35 40 45 50 55 60 65 |
|||
6 | 36 42 48 54 60 66 72 78 |
|||
7 | 49 56 63 70 77 84 91 |
|||
8 | 64 72 80 88 96 104 |
|||
9 | 81 90 99 108 117 |
|||
10 | 100 110 120 130 |
|||
11 | 121 132 143 |
|||
12 | 144 156 |
|||
13 | 169 </pre> |
|||
==={{header|Unicon}}=== |
|||
The Icon solution works in Unicon. |
|||
=={{header|J}}== |
=={{header|J}}== |