用for循环打印矩形,等腰三角形,菱形

1.打印出矩形

#!/bin/bash

for ((i=0;i<5s;i++));do //控制行数
for ((j=0;j<5;j++));do //控制列数
echo -n "*" //打印
done
echo //换行
done
2.打印出等腰三角形

#!/bin/bash

for ((i=0;i<5;i++));do
for ((j=i+1;j<5;j++));do
echo -n " "
done
for ((k=0;k<=i;k++));do
echo -n "* "
done
echo
done
3.三角形

#!/bin/bash

read -p "input line:" line
o=$((($line+1)/2))
for((i=1;i<=$line;i++)); do
if [ $i -le $o ]; then
for ((j=1;j<=$i;j++)); do
echo -n ""
done
else
for ((k=1;k<=$(($line-$i+1));k++));do
echo -n "
"
done
fi
echo
done
4.矩形

#!/bin/bash
read -p "input line:" line
o=$((($lixne+1)/2))
echo $o
for((i=1;i<=$line;i++)); do
if [ $i -le $o ]; then
for ((j=1;j<=$(($o-$i));j++)); do
echo -n " "
done
for((k=1;k<=$((2$i-1));k++));do
echo -n "
"
done
echo
else
for ((m=1;m<=$(($i-$o));m++));do
echo -n " "
done
for((n=1;n<=$((2($line-i+1)-1)); n++));do
echo -n "
"
done
echovivim
fi
echo
done

转载于:https://blog.51cto.com/14259167/2402930

你可能感兴趣的:(用for循环打印矩形,等腰三角形,菱形)