打印九九乘法表
#for语句格式
#!/bin/bash
for (( a = 1 ; a <= 9 ; a++ ))
do
for ((b=1 ; b<=$a ; b++))
do
let sum=b*a
echo -ne "$a*$b=$sum\t"
done
echo ""
done
#while语句格式
#!/bin/bash
a=1
while [ $a -le 9 ]
do
b=1
while [ $b -le $a ]
do
let sum=$a*$b
echo -ne "$a*$b=$sum\t"
let b++
done
echo ""
let a++
done
打印等边三角
#for语句格式,正三角
#!/bin/bash
for ((i=1;i<=9;i++))
do
for ((a=9; a>=$i; a--))
do
echo -n " "
done
for ((b=1; b<=i; b++))
do
echo -n "$i "
done
echo ""
done
#while语句格式,倒三角
#!/bin/bash
i=8
while [ $i -ge 1 ]
do
a=9
while [ $a -ge $i ]
do
echo -n " "
let a--
done
b=1
while [ $b -le $i ]
do
echo -n "$i "
let b++
done
echo""
let i--
done
打印菱形
#while语句格式
#!/bin/bash
i=1
while [ $i -le 9 ]
do
a=9
while [ $a -ge $i ]
do
echo -n " "
let a--
done
b=1
while [ $b -le $i ]
do
echo -n "$i"
let b++
done
c=2
while [ $c -le $i ]
do
echo -n "$i"
let c++
done
echo ""
let i++
done
i=8
while [ $i -ge 1 ]
do
a=9
while [ $a -ge $i ]
do
echo -n " "
let a--
done
b=1
while [ $b -le $i ]
do
echo -n "$i"
let b++
done
c=2
while [ $c -le $i ]
do
echo -n "$i"
let c++
done
echo ""
let i--
done
#for语句格式
for ((i=9; i>0 ; i--))
do
for ((a=1; a<=$i; a++))
do
echo -n " "
done
for ((b=9; b>=$i; b--))
do
echo -n "$i"
done
for ((c=8; c>=$i; c--))
do
echo -n "$i"
done
echo ""
done
for ((i=2; i<=9; i++))
do
for ((a=1; a<=$i; a++))
do
echo -n " "
done
for ((b=9; b>=$i; b--))
do
echo -n "$i"
done
for ((c=8; c>=$i; c--))
do
echo -n "$i"
done
echo ""
done
原文地址:http://blog.51cto.com/13684970/2146262