拓展-用循环语句做出趣味图形
Posted wl.88888888
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了拓展-用循环语句做出趣味图形相关的知识,希望对你有一定的参考价值。
1.直线
#!/bin/bash
for ((a=1;a<=20;a++))
do
echo -n "*"
done
echo ""
2. 矩形
#!/bin/bash
for ((a=1;a<=10;a++))
do
for ((b=1;b<=15;b++))
do
echo -n "*"
done
echo ""
done
3. 正直角三角
for:
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=1;b<=$a;b++))
do
echo -n "*"
done
echo ""
done
while:
#!/bin/bash
a=0
while [ $a -le 9 ]
do
echo -n "*"
b=1
while [ $b -le $a ]
do
echo -n "*"
let b++
done
echo ""
let a++
done
4.倒直角三角
for:
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=9;b>=$a;b--))
do
echo -n "*"
done
echo ""
done
while:
#!/bin/bash
a=0
while [ $a -le 9 ]
do
b=8
while [ $b -ge $a ]
do
echo -n "*"
let b--
done
echo -n "*"
echo ""
let a++
done
5.反三角
for:
#!/bin/bash
for ((a=1;a<=9;a++))
do
# 做一个空格倒三角
for ((b=9;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=$a;c++))
do
echo -n "*"
done
echo ""
done
while:
#!/bin/bash
a=0
while [ $a -le 9 ]
do
b=9
while [ $b -ge $a ]
do
echo -n " "
let b--
done
c=0
while [ $c -le $a ]
do
echo -n "*"
let c++
done
echo ''
let a++
done
6.等腰三角
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=9;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=$[$a*2-1];c++))
do
echo -n "*"
done
echo ""
done
7.平行四边形
for:
#!/bin/bash
for ((i=6;i>=1;i--))
do
for((k=1;k<=i;k++))
do
echo -n " "
done
for (( j=6;j>=1;j--))
do
echo -n "*"
done
echo ""
done
while:
#!/bin/bash
a=0
while [ $a -le 9 ]
do
b=9
while [ $b -ge $a ]
do
echo -n " "
let b--
done
c=1
while [ $c -le $a ]
do
echo -n "*"
let c++
done
d=9
while [ $d -ge $a ]
do
echo -n "*"
let d--
done
echo ""
let a++
done
8.等腰梯形
for:
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=9;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=9;c++))
do
echo -n "*"
done
for ((d=1;d<=$[$a*2-1];d++))
do
echo -n "*"
done
echo ""
done
while:
#!/bin/bash
a=0
while [ $a -le 9 ]
do
b=9
while [ $b -ge $a ]
do
echo -n " "
let b--
done
c=1
while [ $c -le $a ]
do
echo -n "*"
let c++
done
d=1
while [ $d -le $a ]
do
echo -n "*"
let d++
done
e=0
while [ $e -le 9 ]
do
echo -n "*"
let e++
done
echo ""
let a++
done
9.菱形
#!/bin/bash
for ((a=1;a<=9;a++))
do
for ((b=9;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=$[$a*2-1];c++))
do
echo -n "*"
done
echo ""
done
for ((d=1;d<=10;d++))
do
for ((e=2;e<=$d;e++))
do
echo -n " "
done
for ((f=10;f>=$d;f--))
do
echo -n "*"
done
for ((g=9;g>=$d;g--))
do
echo -n "*"
done
echo ""
done
可调节大小:
#!/bin/bash
read -p "请输入数字: " i
for ((a=1;a<=$i;a++))
do
for ((b=$i;b>=$a;b--))
do
echo -n " "
done
for ((c=1;c<=$[2*a-1];c++))
do
echo -n "*"
done
echo ""
done
for ((d=$i-1;d>=1;d--))
do
for ((e=$i;e>=$d;e--))
do
echo -n " "
done
for ((f=$d;f>=1;f--))
do
echo -n "*"
done
for ((g=$d;g>1;g--))
do
echo -n "*"
done
echo ""
done
以上是关于拓展-用循环语句做出趣味图形的主要内容,如果未能解决你的问题,请参考以下文章