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

1.打印出矩形vim

#!/bin/bashbash

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

#!/bin/bashinput

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.三角形it

#!/bin/bashclass

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.矩形im

#!/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
donedi

相關文章
相關標籤/搜索