Created
January 19, 2012 13:40
-
-
Save dekokun/1640094 to your computer and use it in GitHub Desktop.
シェルスクリプトで再帰を用いて階乗計算
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expr $1 + 1 >/dev/null 2>&1 | |
if [ $? -ne 1 -a $? -ne 0 ]; then | |
echo "must be numeric" | |
exit | |
elif [ $1 -lt 0 ]; then | |
echo "must be more than 0" | |
exit | |
elif [ $1 -eq 1 -o $1 -eq 0 ]; then | |
echo 1; | |
else | |
echo $(expr $1 \* $($0 $(expr $1 - 1))) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ex)
./recursive.sh 6
→ 720