话不多说,上代码:

#! /bin/bash
read -p "input a num:" n
function fact(){
sum=0
for ((i=1;i<=n;++i));do
  product=1
  for ((j=1;j<=i;++j));do
    product=$((product*j))
  done
  sum=$((sum+product))
done
return $sum
}
fact
echo "1!+2!+3!...+n!=$?"
 

Logo

更多推荐