#!/bin/bash
while true
do
read -p "please input a number to compute jiecheng: " number
(($number+0)) >/dev/null
if (($? != 0))
then
echo "input error,please input again!"
continue
fi
if (($number <= 0))
then
echo "input number must bigger than 0!please input again!"
continue
fi
sum=1
for i in `seq 1 $number`
do
sum=$((sum*i))
done
echo "${number}! = $sum"
done
shell脚本之计算n的阶乘
最新推荐文章于 2024-06-12 14:02:38 发布