Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
|
|
@ -1,2 +1,4 @@
|
|||
---
|
||||
category:
|
||||
- Simple
|
||||
note: Arithmetic operations
|
||||
|
|
|
|||
|
|
@ -1,22 +1,9 @@
|
|||
BEGIN{
|
||||
for(i=1;i<13;i++){
|
||||
for(j=1;j<13;j++){
|
||||
if(j>=i||j==1){printf "%4d",i*j}
|
||||
else {printf " "}
|
||||
BEGIN {
|
||||
for(i=1;i<=12;i++){
|
||||
for(j=1;j<=12;j++){
|
||||
if(j>=i||j==1){printf "%4d",i*j}
|
||||
else {printf " "}
|
||||
}
|
||||
print
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
|||
13
Task/Multiplication-tables/C/multiplication-tables.c
Normal file
13
Task/Multiplication-tables/C/multiplication-tables.c
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
int main()
|
||||
{
|
||||
int i, j, n = 12;
|
||||
|
||||
for (j = 1; j <= n; j++) printf("%3d%c", j, j - n ? ' ':'\n');
|
||||
for (j = 0; j <= n; j++) printf(j - n ? "----" : "+\n");
|
||||
|
||||
for (i = 1; i <= n; printf("| %d\n", i++))
|
||||
for (j = 1; j <= n; j++)
|
||||
printf(j < i ? " " : "%3d ", i * j);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
print_multiplication_tables = (n) ->
|
||||
width = 4
|
||||
|
||||
pad = (s, n=width, c=' ') ->
|
||||
s = s.toString()
|
||||
result = ''
|
||||
padding = n - s.length
|
||||
while result.length < padding
|
||||
result += c
|
||||
result + s
|
||||
|
||||
s = pad('') + '|'
|
||||
for i in [1..n]
|
||||
s += pad i
|
||||
console.log s
|
||||
|
||||
s = pad('', width, '-') + '+'
|
||||
for i in [1..n]
|
||||
s += pad '', width, '-'
|
||||
console.log s
|
||||
|
||||
|
||||
for i in [1..n]
|
||||
s = pad i
|
||||
s += '|'
|
||||
s += pad '', width*(i - 1)
|
||||
for j in [i..n]
|
||||
s += pad i*j
|
||||
console.log s
|
||||
|
||||
print_multiplication_tables 12
|
||||
10
Task/Multiplication-tables/R/multiplication-tables.r
Normal file
10
Task/Multiplication-tables/R/multiplication-tables.r
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
multiplication_table <- function(n=12)
|
||||
{
|
||||
one_to_n <- 1:n
|
||||
x <- matrix(one_to_n) %*% t(one_to_n)
|
||||
x[lower.tri(x)] <- 0
|
||||
rownames(x) <- colnames(x) <- one_to_n
|
||||
print(as.table(x), zero.print="")
|
||||
invisible(x)
|
||||
}
|
||||
multiplication_table()
|
||||
|
|
@ -1,35 +1,35 @@
|
|||
/*REXX program displays a 12x12 multiplication boxed grid table, grid */
|
||||
/* will be displayed in "boxing" characters for ASCII or EBCDIC.*/
|
||||
parse arg high . /*get optional grid size. */
|
||||
if high=='' then high=12 /*not specified? Use default. */
|
||||
ebcdic='f0'==1 /*is this an EBCDIC machine? */
|
||||
parse arg high . /*get optional grid size from CL.*/
|
||||
if high=='' then high=12 /*not specified? Use default. */
|
||||
ebcdic= 'f0'==1 /*is this an EBCDIC machine? */
|
||||
|
||||
if ebcdic then do /*══════════EBCDIC═══════════════*/
|
||||
bar='fa'x /*vertical bar. */
|
||||
dash='bf'x /*horizontal dash. */
|
||||
bj ='cb'x /*bottom junction. */
|
||||
tj ='cc'x /* top junction. */
|
||||
cj ='8f'x /*center junction (cross). */
|
||||
lj ='eb'x /* left junction. */
|
||||
rj ='ec'x /* right junction. */
|
||||
tlc='ac'x /*top left corner. */
|
||||
trc='bc'x /*top right corner. */
|
||||
blc='ab'x /*bottom left corner. */
|
||||
brc='bb'x /*bottom right corner. */
|
||||
end
|
||||
else do /*══════════ASCII════════════════*/
|
||||
bar='b3'x /*vertical bar. */
|
||||
dash='c4'x /*horizontal dash. */
|
||||
bj ='c1'x /*bottom junction. */
|
||||
tj ='c2'x /* top junction. */
|
||||
cj ='c5'x /*center junction (cross). */
|
||||
lj ='c3'x /* left junction. */
|
||||
rj ='b4'x /* right junction. */
|
||||
tlc='da'x /*top left corner. */
|
||||
trc='bf'x /*top right corner. */
|
||||
blc='c0'x /*bottom left corner. */
|
||||
brc='d9'x /*bottom right corner. */
|
||||
end
|
||||
if ebcdic then do /*══════════EBCDIC═══════════════*/
|
||||
bar='fa'x /*vertical bar. */
|
||||
dash='bf'x /*horizontal dash. */
|
||||
bj ='cb'x /*bottom junction. */
|
||||
tj ='cc'x /* top junction. */
|
||||
cj ='8f'x /*center junction (cross). */
|
||||
lj ='eb'x /* left junction. */
|
||||
rj ='ec'x /* right junction. */
|
||||
tlc='ac'x /*top left corner. */
|
||||
trc='bc'x /*top right corner. */
|
||||
blc='ab'x /*bottom left corner. */
|
||||
brc='bb'x /*bottom right corner. */
|
||||
end
|
||||
else do /*══════════ASCII════════════════*/
|
||||
bar='b3'x /*vertical bar. */
|
||||
dash='c4'x /*horizontal dash. */
|
||||
bj ='c1'x /*bottom junction. */
|
||||
tj ='c2'x /* top junction. */
|
||||
cj ='c5'x /*center junction (cross). */
|
||||
lj ='c3'x /* left junction. */
|
||||
rj ='b4'x /* right junction. */
|
||||
tlc='da'x /*top left corner. */
|
||||
trc='bf'x /*top right corner. */
|
||||
blc='c0'x /*bottom left corner. */
|
||||
brc='d9'x /*bottom right corner. */
|
||||
end
|
||||
|
||||
cell=cj || copies(dash,5) /*define the top of the cell. */
|
||||
sep=copies(cell,high+1)rj /*build the table separator. */
|
||||
|
|
@ -38,7 +38,7 @@ width=length(cell)-1 /*width of the table cells. */
|
|||
size=width-1 /*width for table numbers. */
|
||||
box.=left('',width) /*construct all the cells. */
|
||||
|
||||
do j=0 to high /*step through zero to H (12). */
|
||||
do j=0 to high /*step through zero to H (12). */
|
||||
_=right(j,size-1)'x ' /*build "label"/border number. */
|
||||
box.0.j=_ /*build top label cell. */
|
||||
box.j.0=_ /*build left label cell. */
|
||||
|
|
@ -49,22 +49,22 @@ box.0.0=centre('times',width) /*redefine box.0.0 with 'X'. */
|
|||
do row=1 for high /*step through 1 to H (12). */
|
||||
do col=row to high /*step through row to H (12). */
|
||||
box.row.col=right(row*col,size)' ' /*build a mult. cell. */
|
||||
end /*col*/
|
||||
end /*row*/
|
||||
end /*col*/
|
||||
end /*row*/
|
||||
|
||||
do row=0 to high /*step through all the lines. */
|
||||
do row=0 to high /*step through all the lines. */
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
if row==0 then do
|
||||
asep=overlay(tlc,asep,1) /*make a better tlc. */
|
||||
asep=overlay(trc,asep,sepL) /*make a better trc. */
|
||||
asep=translate(asep,tj,cj) /*make a better tj. */
|
||||
end
|
||||
else asep=overlay(lj,asep,1) /*make a better lj. */
|
||||
if row==0 then do
|
||||
asep=overlay(tlc,asep,1) /*make a better tlc. */
|
||||
asep=overlay(trc,asep,sepL) /*make a better trc. */
|
||||
asep=translate(asep,tj,cj) /*make a better tj. */
|
||||
end
|
||||
else asep=overlay(lj,asep,1) /*make a better lj. */
|
||||
|
||||
say asep /*display a table grid line. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
call buildLine row /*build one line of the grid. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
call buildLine row /*build one line of the grid. */
|
||||
if row==0 then call buildLine 00 /*display a blank grid line. */
|
||||
end /*row*/
|
||||
|
||||
asep=sep /*allow use of a modified sep. */
|
||||
|
|
@ -74,7 +74,7 @@ asep=translate(asep,bj,cj) /*make a better bot junction. */
|
|||
say asep /*display a table grid line. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────BUILDLINE subroutine────────────────*/
|
||||
buildLine: w=; parse arg arow /*start with a blank cell. */
|
||||
buildLine: w=; parse arg arow /*start with a blank cell. */
|
||||
|
||||
do col=0 to high /*step through 0 to H (12). */
|
||||
w=w||bar||box.arow.col /*build one cell at a time. */
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
Sub Main()
|
||||
Const nmax = 12, xx = 3
|
||||
Const x = xx + 1
|
||||
Dim i As Integer, j As Integer, s As String
|
||||
s = String(xx, " ") & " |"
|
||||
For j = 1 To nmax
|
||||
s = s & Right(String(x, " ") & j, x)
|
||||
Next j
|
||||
Debug.Print s
|
||||
s = String(xx, "-") & " +"
|
||||
For j = 1 To nmax
|
||||
s = s & " " & String(xx, "-")
|
||||
Next j
|
||||
Debug.Print s
|
||||
For i = 1 To nmax
|
||||
s = Right(String(xx, " ") & i, xx) & " |"
|
||||
For j = 1 To nmax
|
||||
If j >= i _
|
||||
Then s = s & Right(String(x, " ") & i * j, x) _
|
||||
Else s = s & String(x, " ")
|
||||
Next j
|
||||
Debug.Print s
|
||||
Next i
|
||||
End Sub 'Main
|
||||
Loading…
Add table
Add a link
Reference in a new issue