循环打印等腰三角形

1. awk while循环 打印等腰三角形

awk 'BEGIN {i=1;while(i<=10){j=1;while(j<=(10-i)){printf " "; j++;}j=1;while(j<=(2*i-1)){printf "*";j++;}printf "\n";i++;}}'

2.awk for 循环 打印等腰三角形

awk 'BEGIN {for(i=1;i<=10;i++){for(j=1;j<=10-i;j++){printf " ";}for(j=1;j<=(2*i-1);j++){printf "*";}printf "\n";}}'

3.脚本打印

read -p "请输入一个数字:" Line
for ((i=1; i<=Line; i++))
do
    for ((j=$Line-$i; j>0; j--));
    do
        echo -n ' '
    done
    for ((h=1; h<=$((2*$i-1)); h++))
    do
        echo -n '*'
    done
    echo
done

4.命令行打印

for((i=1;i<10;i++));do for((j=10;j>i;j--));do echo -n " ";done;for((m=1;m<=i;m++));do echo -n "* "; done;echo "";done

你可能感兴趣的:(bash)