Shell脚本之打印99乘法表(两种方法)

x33g5p2x  于2021-10-21 转载在 Shell  
字(0.3k)|赞(0)|评价(0)|浏览(691)

法一:

#!/bin/bash
n=1
while [ $n -lt 10 ]
do
  for ((m=1;m<=$n;m++))
   do
    echo -n -e "${m}x${n}=$[m*n]\t"
   done
echo
n=$((n+1))
done

**法二: **

#!/bin/bash
for j in {1..9}
do
for i in `seq $j`
do
echo -e  -n "${i}x${j}=$[ $i * $j ]\t"
done
echo
done

**倒三角: **

#!/bin/bash
for j in {9..1..-1}
do
for i in `seq $j`
do
echo -e  -n "${i}x${j}=$[ $i * $j ]\t"
done
echo
done

相关文章