代码:
#! /bin/bash
#这是一个用函数写的的例子,
function factorial
{
ret_val=0
factarg=0
if (( $1<=1 ))
then
res=1
return 0
else
(( factarg=$1 - 1 ))
factorial $factarg
(( ret_val=$1 * $res ))
res=$ret_val
return 0
fi
}
factorial $1
echo "Factorial of $1 is:$res"
[javalee@Linux javalee]$ sh digui 6
Factorial of 6 is:720
阅读(1600) | 评论(0) | 转发(0) |