Created
February 20, 2013 06:10
-
-
Save toya33/4993336 to your computer and use it in GitHub Desktop.
3. 2.で作成したFizzBuzz2.shを元にforまたはwhileまたはuntilを使っていた場合にはそれらループ制御構文を用いずに関数の再帰によるループで、或いは元々関数の再帰によるループで実装していた場合は逆にforまたはwhileまたはuntilを用いたループでFizzBuzz3.shを作成する(30点) 「再帰関数」
This file contains 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
#!/bin/sh | |
#関数再帰によるFizzBuzz | |
FizzBuzz(){ | |
if [ `expr $a % 15` -eq 0 ]; then | |
echo "FizzBuzz " | |
elif [ `expr $a % 3` -eq 0 ]; then | |
echo "Fizz " | |
elif [ `expr $a % 5` -eq 0 ]; then | |
echo "Buzz" | |
else | |
echo "$a " | |
fi | |
if [ $a -ge $b ]; then | |
echo OK; | |
exit 0; | |
fi | |
a=`expr $a + 1` | |
FizzBuzz a b | |
} | |
if [ $1 -ge 0 -a $2 -ge 0 ]; then | |
export a=$1 | |
export b=$2 | |
FizzBuzz a b | |
else | |
echo "2つの非負数を引数にしてください。" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment