码迷,mamicode.com
首页 > 系统相关 > 详细

shell脚本

时间:2019-11-14 09:57:35      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:ash   pre   width   alt   image   com   shell   sharp   nbsp   

1.n的阶乘。

#!
#
f() {
     if [ $1 -lt 1 ];then
        echo 1
     else
        i=$[$1*$(f $[$1-1])]
        echo $i
     fi
}
f 5

技术图片

2.斐波那契函数。(1,1,2,3,5,8,13,21,34,55....)

#!/bin/bash
#

fact() {
      if [ $1 -lt 3 ];then
       echo 1
      else 
         i=$[$(fact $[$1-1])+ $(fact $[$1-2])]
         echo $i
      fi
}
fact 8

技术图片

 

 

shell脚本

标签:ash   pre   width   alt   image   com   shell   sharp   nbsp   

原文地址:https://www.cnblogs.com/COO-zsy/p/11589522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!