标签:输出 let targe htm 计算 show end 分隔符 blank
shell
#! /bin/bash
#外层循环
for ((i=1;i<=9;i++))
do
#内层循环
for ((j=1;j<=i;j++))
do
#计算2个数的乘积
let "product=i*j"
#输出乘积
printf "i*i?j=$product"
#输出空格分隔符
if [[ "$product" -gt 9 ]]
then
printf " "
else
printf " "
fi
done
echo
done
sed
seq 9 | sed ‘H;g‘ | awk -v RS=‘‘ ‘{for(i=1;i<=NF;i++)printf("%dx%d=%d%s", i, NR, i*NR, i==NR?"\n":"\t")}‘
awk
awk ‘BEGIN{for(i=1;i<=9;i++){for(j=1;j<=i;j++)printf "%s*%s=% 2s ",j,i,i*j;print a}}‘
即
awk ‘
BEGIN {
for(i=1;i<=9;i++){
for(j=1;j<=i;j++)
printf "%s*%s=% 2s ",j,i,i*j;
print ""
}
}‘
#Python2.7:
for x in range(1,10):
for y in range(1,x+1):
print x, "x", y, "=", x*y, "\t",
print "\n"
#Python3.6:
for i in range(1,10):
for j in range(i,10):
print("%d*%d=%2d" % (i,j,i*j),end=" ")
print("")
showtooltip
打印乘法口诀表(shell/sed/awk/python)
标签:输出 let targe htm 计算 show end 分隔符 blank
原文地址:https://www.cnblogs.com/coding8832/p/14468914.html