多层for循环之显示图形
一、直线
#!/bin/bash
for ((i=1;i<=20;i++))
do
echo -n "*"
done
echo ""
二、9*9乘法口径表
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=1;b<=$a;b++))
do
c=$[$b * $a]
echo -n -e "$b*$a=$c\t"
done
echo ""
done
三、矩形
#!/bin/bash
for ((a=1;a<=10;a++))
do
for ((b=1;b<=5;b++))
do
echo -n "*"
done
echo ""
done
四、三角形
1. 直角三角形
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n "*"
done
echo ""
done
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=10;j>=$i;j--))
do
echo -n " "
done
for ((k=1;k<=$i;k++))
do
echo -n "*"
done
echo ""
done
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=10;j>=$i;j--))
do
echo -n "*"
done
echo ""
done
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n " "
done
for ((k=10;k>=$i;k--))
do
echo -n "*"
done
echo ""
done
2. 等腰三角形
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=10;j>=$i;j--))
do
echo -n " "
done
for ((k=1;k<=$i;k++))
do
echo -n "*"
done
for ((l=2;l<=$i;l++))
do
echo -n "*"
done
echo ""
done
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=1;j<=$i;j++))
do
echo -n " "
done
for ((k=10;k>=$i;k--))
do
echo -n "*"
done
for ((l=9;l>=$i;l--))
do
echo -n "*"
done
echo ""
done
五、菱形
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=10;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=$a;c++))
do
echo -n "*"
done
for ((d=2;d<=$a;d++))
do
echo -n "*"
done
echo ""
done
for ((e=1;e<=10;e++))
do
for ((f=1;f<=$e;f++))
do
echo -n " "
done
for ((g=10;g>=$e;g--))
do
echo -n "*"
done
for ((h=9;h>=$e;h--))
do
echo -n "*"
done
echo ""
done
六、等腰梯形
#!/bin/bash
for ((i=1;i<=10;i++))
do
for ((j=10;j>=$i;j--))
do
echo -n " "
done
for ((k=1;k<=$i;k++))
do
echo -n "*"
done
for ((m=1;m<=8;m++))
do
echo -n "*"
done
for ((n=1;n<=$i;n++))
do
echo -n "*"
done
echo ""
done