shell编程实现五种九九乘法表

这是Linux实用技术这门课老师的实验课内容
shell编程实现五种九九乘法表_第1张图片

上代码

q1:

#!/bin/bash
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
	echo -ne "$i*$j=$[$i*$j]\t "
done
echo ""
done


q2:

#!/bin/bash
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
echo -ne "$i*$j=$[$i*$j]\t "
fi
done
echo ""
done


q3:

#!/bin/bash
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 -ge $j ]
then
echo -ne "$i*$j=$[$i*$j]\t "
fi
done
echo ""
done


q4:

#!/bin/bash
k=9
for i in 1 2 3 4 5 6 7 8 9
do
j=1
while [ $j -lt $i ]
do
echo -e "	\c"
j=`expr $j + 1`
done
while [ $j -lt 10 ]
do
sum=`expr $i \* $j`
echo -e "$i*$j=${sum}	\c"
j=`expr $j + 1`
done		
echo " "		
done


q5:

#!/bin/bash
k=9
for i in 1 2 3 4 5 6 7 8 9
do
j=1
while [ $j -lt $k ]
do
echo -e "	\c"
j=`expr $j + 1`	
done
while [ $j -lt 10 ]
do
l=`expr 10 - $j`
sum=`expr $i \* $l`
echo -e "$i*$l=${sum}	\c"
j=`expr $j + 1`
done
k=`expr $k - 1`
echo " "
done


shell编程实现五种九九乘法表_第2张图片

你可能感兴趣的:(shell编程实现五种九九乘法表)