1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| [root@vm-101 ~] #!/bin/bash
read -p "输入杨辉三角的大小:" size
list=(0 1)
for ((i=1; i<=$size; i++)) do for ((a=$[ $size - $i ]; a>0; a--)) do echo -n " " done
list_tmp=(0)
for ((b=1; b<${#list[@]}; b++)) do var=$[ ${list[$[b-1]]} + ${list[b]} ] echo -n " $var" list_tmp=(${list_tmp[@]} $var) done list=(${list_tmp[@]} 0) echo done
exit 0
[root@vm-101 ~] 输入杨辉三角的大小:5 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 [root@vm-101 ~] 输入杨辉三角的大小:7 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1
|