if [ $# -ne 1 ]
then
echo "输入一个整数"
exit 1
fi
i=1
sum=1
while [ $i -le $1 ]
do
sum=$((sum * i))
i=$((i+1))
done
echo $sum
这样可实现你的要求
#!/bin/sh
exponentiation()
{
number=$1
product=1
for((i=1;i<=$number;i++))
do
product=$(($product * $i))
done
echo $product
}
GETFROM=$1
exponentiation $GETFROM
脚本保存为test.sh
chmod u+x test.sh
./test.sh N (N为你需要计算幂的数字)
./test.sh 10
3628800
factorial(){
SUM=1
for i in `seq $1`
do
SUM=$(($SUM*$i))
done
echo $SUM
}
#test
factorial 10
fuction sn(n)
dim i as integer
sn=1
for i= 1 to n
sn=sn*i
next
end fuction