打印乘法口诀表(shell/sed/awk/python)

2021-06-10 06:02

阅读:681

标签:输出   let   targe   htm   计算   show   end   分隔符   blank   

shell
#! /bin/bash
#外层循环
for ((i=1;i
do
        #内层循环
        for ((j=1;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
awk
awk ‘BEGIN{for(i=1;i
awk ‘
BEGIN {
    for(i=1;i
        for(j=1;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


评论


亲,登录后才可以留言!