标签:bash 三角形 for循环 NPU line for lse 控制 one
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.三角形
*
**
* $o 4
$i = 5 3 $line-$i+1
** 6 2
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
标签:bash 三角形 for循环 NPU line for lse 控制 one
原文地址:https://blog.51cto.com/14259167/2402930