shell for循环练习题99乘法表

#!/bin/bash
# Crushlinux 
# 2017-03-10 

for one in {1..9}
do
	for ((two=1;two<=$one;two++))
	do
		echo -n "$two x $one = $(($one*$two))  "
	done
	echo
done

版本二:

#!/bin/bash
#99乘法表
 for i in {1..9}
 do
    for j in {1..9}
        do
         echo -n "$j*$i=$(expr $j \* $i) "
       if [ $j == $i ];then
         echo -e '\n'    #-e 允许对后面\做出解释
        break
      fi
    done
done

版本三:

#!/bin/bash

for i in {1..9}
do
	for j in {1..9}
	do
		if [ $j -le $i ]
		then
			echo  -n "$j x $i = $(($j*$i))   "

		fi
	done
	echo 
done

  

posted @ 2017-04-20 13:36  房佳亮  阅读(929)  评论(0编辑  收藏  举报