[root@centos7 ~]# ./max.sh
Please input first digits :100
Please input second digits :200
最大的数是200
2、斐波那契数列又称黄金分割数列,因数学家列昂纳多·斐波那契以兔子繁殖为例子而引入,故又称为“兔子数列”,指的是这样一个数列:0、1、1、2、3、5、8、13、21、34、……,斐波纳契数列以如下被以递归的方法定义:F(0)=0, F(1)=1,F(n)=F(n-1)+F(n-2)(n≥2),利用函数,求 n 阶斐波那契数列;
#!/bin/bashfunction hanoi(){if[$1 -eq 1 ];thenecho move $2 to $4else
hanoi $(($1-1))$2$4$3echo move $2 to $4
hanoi $(($1-1))$3$2$4fi}# 5个盘,修改下一行的数字,指定盘子数量
hanoi 5 'A''B''C'
执行结果
[root@centos7 ~]# ./hannota.sh
move A to C
move A to B
move C to B
move A to C
move B to A
move B to C
move A to C
move A to B
move C to B
move C to A
move B to A
move C to B
move A to C
move A to B
move C to B
move A to C
move B to A
move B to C
move A to C
move B to A
move C to B
move C to A
move B to A
move B to C
move A to C
move A to B
move C to B
move A to C
move B to A
move B to C
move A to C