最短shell代码实现乘法表

Time: 四月 18, 2013
Category: Programming practices

the first version:

[shell]
for i in {1..5}; do for j in {1..5}; do let k=$i*$j; echo $i*$j=$k; done; done;
[/shell]

then, i research for a while, and write the 2rd

[shell]
seq 5 | awk '{for(i=1;i<=$1;i++){printf($1 "*"i"="i*$1" ")};print""}'
[/shell]

Leave a Comment