#!/bin/bash
fact()
{
local num=$1
local fac
if ((num==1))
then
fac=1
else
((dec=num-1))
fact $dec
fac=$?
fac=`expr $num \* $fac`
fi
return $fac
}
fact 5
echo $?
#!/bin/bash
fact()
{
local num=$1
local fac
if ((num==1))
then
fac=1
else
((dec=num-1))
fact $dec
fac=$?
fac=`expr $num \* $fac`
fi
return $fac
}
fact 5
echo $?
本文标题:shell 递归求阶乘
本文链接:https://www.haomeiwen.com/subject/zgxrxctx.html
网友评论