Multiplication tables: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (fix markup) |
(Dialects of BASIC moved to the BASIC section.) |
||
Line 1,249: | Line 1,249: | ||
11 | 121 132 |
11 | 121 132 |
||
12 | 144</pre> |
12 | 144</pre> |
||
=={{header|ASIC}}== |
|||
{{trans|Modula-2}} |
|||
<syntaxhighlight lang="basic"> |
|||
REM Multiplication tables |
|||
N = 12 |
|||
PREDN = N - 1 |
|||
WDTH = 3 |
|||
CLS |
|||
FOR J = 1 TO PREDN |
|||
INTVAL = J |
|||
GOSUB PRINTINT: |
|||
PRINT " "; |
|||
NEXT J |
|||
INTVAL = N |
|||
GOSUB PRINTINT: |
|||
PRINT |
|||
FOR J = 0 TO PREDN |
|||
PRINT "----"; |
|||
NEXT J |
|||
PRINT "+" |
|||
FOR I = 1 TO N |
|||
WDTH = 3 |
|||
FOR J = 1 TO N |
|||
IF J < I THEN |
|||
PRINT " "; |
|||
ELSE |
|||
INTVAL = I * J |
|||
GOSUB PRINTINT: |
|||
PRINT " "; |
|||
ENDIF |
|||
NEXT J |
|||
PRINT "| "; |
|||
INTVAL = I |
|||
WDTH = 2 |
|||
GOSUB PRINTINT: |
|||
PRINT |
|||
NEXT I |
|||
END |
|||
PRINTINT: |
|||
REM Writes the value of INTVAL in a field of the given WDTH |
|||
S2$ = STR$(INTVAL) |
|||
S2$ = LTRIM$(S2$) |
|||
SPNUM = LEN(S2$) |
|||
SPNUM = WDTH - SPNUM |
|||
S1$ = SPACE$(SPNUM) |
|||
PRINT S1$; |
|||
PRINT S2$; |
|||
RETURN |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 7 8 9 10 11 12 |
|||
------------------------------------------------+ |
|||
1 2 3 4 5 6 7 8 9 10 11 12 | 1 |
|||
4 6 8 10 12 14 16 18 20 22 24 | 2 |
|||
9 12 15 18 21 24 27 30 33 36 | 3 |
|||
16 20 24 28 32 36 40 44 48 | 4 |
|||
25 30 35 40 45 50 55 60 | 5 |
|||
36 42 48 54 60 66 72 | 6 |
|||
49 56 63 70 77 84 | 7 |
|||
64 72 80 88 96 | 8 |
|||
81 90 99 108 | 9 |
|||
100 110 120 | 10 |
|||
121 132 | 11 |
|||
144 | 12 |
|||
</pre> |
|||
=={{header|AutoHotkey}}== |
=={{header|AutoHotkey}}== |
||
Line 1,457: | Line 1,389: | ||
=={{header|BASIC}}== |
=={{header|BASIC}}== |
||
==={{header|Applesoft BASIC}}=== |
==={{header|Applesoft BASIC}}=== |
||
<syntaxhighlight lang="applesoftbasic">100 M = 12 |
<syntaxhighlight lang="applesoftbasic">100 M = 12 |
||
Line 1,470: | Line 1,400: | ||
180 PRINT TAB(FN T(J)) MID$(" ", 1, 3 - LEN(V$) - (J < 4)) V$; |
180 PRINT TAB(FN T(J)) MID$(" ", 1, 3 - LEN(V$) - (J < 4)) V$; |
||
190 NEXT J, N</syntaxhighlight> |
190 NEXT J, N</syntaxhighlight> |
||
==={{header|ASIC}}=== |
|||
{{trans|Modula-2}} |
|||
<syntaxhighlight lang="basic"> |
|||
REM Multiplication tables |
|||
N = 12 |
|||
PREDN = N - 1 |
|||
WDTH = 3 |
|||
CLS |
|||
FOR J = 1 TO PREDN |
|||
INTVAL = J |
|||
GOSUB PRINTINT: |
|||
PRINT " "; |
|||
NEXT J |
|||
INTVAL = N |
|||
GOSUB PRINTINT: |
|||
PRINT |
|||
FOR J = 0 TO PREDN |
|||
PRINT "----"; |
|||
NEXT J |
|||
PRINT "+" |
|||
FOR I = 1 TO N |
|||
WDTH = 3 |
|||
FOR J = 1 TO N |
|||
IF J < I THEN |
|||
PRINT " "; |
|||
ELSE |
|||
INTVAL = I * J |
|||
GOSUB PRINTINT: |
|||
PRINT " "; |
|||
ENDIF |
|||
NEXT J |
|||
PRINT "| "; |
|||
INTVAL = I |
|||
WDTH = 2 |
|||
GOSUB PRINTINT: |
|||
PRINT |
|||
NEXT I |
|||
END |
|||
PRINTINT: |
|||
REM Writes the value of INTVAL in a field of the given WDTH |
|||
S2$ = STR$(INTVAL) |
|||
S2$ = LTRIM$(S2$) |
|||
SPNUM = LEN(S2$) |
|||
SPNUM = WDTH - SPNUM |
|||
S1$ = SPACE$(SPNUM) |
|||
PRINT S1$; |
|||
PRINT S2$; |
|||
RETURN |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 5 6 7 8 9 10 11 12 |
|||
------------------------------------------------+ |
|||
1 2 3 4 5 6 7 8 9 10 11 12 | 1 |
|||
4 6 8 10 12 14 16 18 20 22 24 | 2 |
|||
9 12 15 18 21 24 27 30 33 36 | 3 |
|||
16 20 24 28 32 36 40 44 48 | 4 |
|||
25 30 35 40 45 50 55 60 | 5 |
|||
36 42 48 54 60 66 72 | 6 |
|||
49 56 63 70 77 84 | 7 |
|||
64 72 80 88 96 | 8 |
|||
81 90 99 108 | 9 |
|||
100 110 120 | 10 |
|||
121 132 | 11 |
|||
144 | 12 |
|||
</pre> |
|||
==={{header|BASIC256}}=== |
==={{header|BASIC256}}=== |
||
Line 1,656: | Line 1,654: | ||
<pre> |
<pre> |
||
| 1 2 3 4 5 6 7 8 9 10 11 12 |
| 1 2 3 4 5 6 7 8 9 10 11 12 |
||
---+------------------------------------------------ |
|||
1| 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
2| 4 6 8 10 12 14 16 18 20 22 24 |
|||
3| 9 12 15 18 21 24 27 30 33 36 |
|||
4| 16 20 24 28 32 36 40 44 48 |
|||
5| 25 30 35 40 45 50 55 60 |
|||
6| 36 42 48 54 60 66 72 |
|||
7| 49 56 63 70 77 84 |
|||
8| 64 72 80 88 96 |
|||
9| 81 90 99 108 |
|||
10| 100 110 120 |
|||
11| 121 132 |
|||
12| 144 |
|||
</pre> |
|||
==={{header|Gambas}}=== |
|||
'''[https://gambas-playground.proko.eu/?gist=3a3a987766a9a9a383b3e0e8a65d9ea2 Click this link to run this code]''' |
|||
<syntaxhighlight lang="gambas">'Code 'stolen' from Free Basic and altered to work in Gambas |
|||
Public Sub Main() |
|||
Dim i, j As Integer |
|||
Print " X|"; |
|||
For i = 1 To 12 |
|||
Print Format(i, "####"); |
|||
Next |
|||
Print |
|||
Print "---+"; String(48, "-") |
|||
For i = 1 To 12 |
|||
Print Format(i, "###"); |
|||
Print "|"; Space(4 * (i - 1)); |
|||
For j = i To 12 |
|||
Print Format(i * j, "####"); |
|||
Next |
|||
Print |
|||
Next |
|||
End</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
X| 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
---+------------------------------------------------ |
---+------------------------------------------------ |
||
1| 1 2 3 4 5 6 7 8 9 10 11 12 |
1| 1 2 3 4 5 6 7 8 9 10 11 12 |
||
Line 1,673: | Line 1,714: | ||
==={{header|GW-BASIC}}=== |
==={{header|GW-BASIC}}=== |
||
{{trans|Modula-2}} |
{{trans|Modula-2}} |
||
{{works with|BASICA}} |
|||
{{works with|PC-BASIC|any}} |
{{works with|PC-BASIC|any}} |
||
<syntaxhighlight lang=" |
<syntaxhighlight lang="gwbasic"> |
||
10 ' Multiplication Tables |
10 ' Multiplication Tables |
||
20 LET N% = 12 |
20 LET N% = 12 |
||
Line 1,955: | Line 1,997: | ||
0 OK, 0:105</pre> |
0 OK, 0:105</pre> |
||
==={{header|VBA}}=== |
|||
<syntaxhighlight lang="vb"> |
|||
Option Explicit |
|||
Sub Multiplication_Tables() |
|||
Dim strTemp As String, strBuff As String |
|||
Dim i&, j&, NbDigits As Byte |
|||
'You can adapt the following const : |
|||
Const NB_END As Byte = 12 |
|||
Select Case NB_END |
|||
Case Is < 10: NbDigits = 3 |
|||
Case 10 To 31: NbDigits = 4 |
|||
Case 31 To 100: NbDigits = 5 |
|||
Case Else: MsgBox "Number too large": Exit Sub |
|||
End Select |
|||
strBuff = String(NbDigits, " ") |
|||
For i = 1 To NB_END |
|||
strTemp = Right(strBuff & i, NbDigits) |
|||
For j = 2 To NB_END |
|||
If j < i Then |
|||
strTemp = strTemp & strBuff |
|||
Else |
|||
strTemp = strTemp & Right(strBuff & j * i, NbDigits) |
|||
End If |
|||
Next j |
|||
Debug.Print strTemp |
|||
Next i |
|||
End Sub |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
2 4 6 8 10 12 14 16 18 20 22 24 |
|||
3 9 12 15 18 21 24 27 30 33 36 |
|||
4 16 20 24 28 32 36 40 44 48 |
|||
5 25 30 35 40 45 50 55 60 |
|||
6 36 42 48 54 60 66 72 |
|||
7 49 56 63 70 77 84 |
|||
8 64 72 80 88 96 |
|||
9 81 90 99 108 |
|||
10 100 110 120 |
|||
11 121 132 |
|||
12 144</pre> |
|||
==={{header|Visual Basic}}=== |
==={{header|Visual Basic}}=== |
||
Line 4,098: | Line 4,186: | ||
11 121 132 |
11 121 132 |
||
12 144 |
12 144 |
||
</pre> |
|||
=={{header|Gambas}}== |
|||
'''[https://gambas-playground.proko.eu/?gist=3a3a987766a9a9a383b3e0e8a65d9ea2 Click this link to run this code]''' |
|||
<syntaxhighlight lang="gambas">'Code 'stolen' from Free Basic and altered to work in Gambas |
|||
Public Sub Main() |
|||
Dim i, j As Integer |
|||
Print " X|"; |
|||
For i = 1 To 12 |
|||
Print Format(i, "####"); |
|||
Next |
|||
Print |
|||
Print "---+"; String(48, "-") |
|||
For i = 1 To 12 |
|||
Print Format(i, "###"); |
|||
Print "|"; Space(4 * (i - 1)); |
|||
For j = i To 12 |
|||
Print Format(i * j, "####"); |
|||
Next |
|||
Print |
|||
Next |
|||
End</syntaxhighlight> |
|||
Output: |
|||
<pre> |
|||
X| 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
---+------------------------------------------------ |
|||
1| 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
2| 4 6 8 10 12 14 16 18 20 22 24 |
|||
3| 9 12 15 18 21 24 27 30 33 36 |
|||
4| 16 20 24 28 32 36 40 44 48 |
|||
5| 25 30 35 40 45 50 55 60 |
|||
6| 36 42 48 54 60 66 72 |
|||
7| 49 56 63 70 77 84 |
|||
8| 64 72 80 88 96 |
|||
9| 81 90 99 108 |
|||
10| 100 110 120 |
|||
11| 121 132 |
|||
12| 144 |
|||
</pre> |
</pre> |
||
Line 7,067: | Line 7,112: | ||
12 | 144 |
12 | 144 |
||
</pre> |
</pre> |
||
=={{header|VBA}}== |
|||
<syntaxhighlight lang="vb"> |
|||
Option Explicit |
|||
Sub Multiplication_Tables() |
|||
Dim strTemp As String, strBuff As String |
|||
Dim i&, j&, NbDigits As Byte |
|||
'You can adapt the following const : |
|||
Const NB_END As Byte = 12 |
|||
Select Case NB_END |
|||
Case Is < 10: NbDigits = 3 |
|||
Case 10 To 31: NbDigits = 4 |
|||
Case 31 To 100: NbDigits = 5 |
|||
Case Else: MsgBox "Number too large": Exit Sub |
|||
End Select |
|||
strBuff = String(NbDigits, " ") |
|||
For i = 1 To NB_END |
|||
strTemp = Right(strBuff & i, NbDigits) |
|||
For j = 2 To NB_END |
|||
If j < i Then |
|||
strTemp = strTemp & strBuff |
|||
Else |
|||
strTemp = strTemp & Right(strBuff & j * i, NbDigits) |
|||
End If |
|||
Next j |
|||
Debug.Print strTemp |
|||
Next i |
|||
End Sub |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> 1 2 3 4 5 6 7 8 9 10 11 12 |
|||
2 4 6 8 10 12 14 16 18 20 22 24 |
|||
3 9 12 15 18 21 24 27 30 33 36 |
|||
4 16 20 24 28 32 36 40 44 48 |
|||
5 25 30 35 40 45 50 55 60 |
|||
6 36 42 48 54 60 66 72 |
|||
7 49 56 63 70 77 84 |
|||
8 64 72 80 88 96 |
|||
9 81 90 99 108 |
|||
10 100 110 120 |
|||
11 121 132 |
|||
12 144</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |