要求如下图:
效果图:
源码:
appledeMacBook-Pro:~ apple$ cat 1607084207zy.sh
for i in 1 2 3 4 5 6 7 8 9
do
for j in 1 2 3 4 5 6 7 8 9
do
printf "$i*$j=$(($i*$j))\t"
done
echo
done
appledeMacBook-Pro:~ apple$ cat 1607084207zy2.sh
for i in 1 2 3 4 5 6 7 8 9
do
for((j=1;j<=i;j++))
do
printf "$i*$j=$(($i*$j))\t"
done
echo
done
appledeMacBook-Pro:~ apple$ cat 1607084207zy3.sh
for i in 1 2 3 4 5 6 7 8 9
do
for((j=i;j<=9;j++))
do
printf "$i*$j=$(($i*$j))\t"
done
echo
done
appledeMacBook-Pro:~ apple$ cat 1607084207zy4.sh
for i in 1 2 3 4 5 6 7 8 9
do
for j in 9 8 7 6 5 4 3 2 1
do
if test $i -ge $j;
then printf "$i*$j=$(($i*$j))\t"
else
printf "\t"
fi
done
echo
done
appledeMacBook-Pro:~ apple$ cat 1607084207zy5.sh
for i in 1 2 3 4 5 6 7 8 9
do
for j in 1 2 3 4 5 6 7 8 9
do
if [ $i -le $j ];
then printf "$i*$j=$(($i*$j))\t"
else
printf "\t"
fi
done
echo
done
总结:
仍不能较熟练的使用echo显示内容,只能借助printf打印出制表符直线对齐,而用echo则不能实现效果。
五种不同形式的乘法表就是遍历的条件不同