#!/bin/bash
#【程序61】
#题目:打印出杨辉三角形(要求打印出10行如下图)
#1.程序分析:
a=()
for i in {0..9};do
for j in {0..9};do
a[$((i*10 + j))]=0
done
done
for i in {0..9};do
a[$((i*10))]=1
a[$((i*10 + i))]=1
done
for i in {2..9};do
for j in $(seq 1 $((i - 1)) );do
a[$((i*10 + j))]=$((${a[$(( (i - 1)*10 + j -1))]} + ${a[$(( (i - 1)*10 + j))]}))
done
done
for i in {0..9};do
for j in {0..9};do
if [ $j -gt $i ];then break;fi
echo -n "${a[$((i * 10 + j))]} "
done
echo
done
阅读(836) | 评论(0) | 转发(0) |