Created
February 20, 2013 06:08
-
-
Save toya33/4993327 to your computer and use it in GitHub Desktop.
2. 1.で作成したFizzBuzz1.shを元に任意の非負整数の範囲A以上B以下についてコマンド実行時に引数を取得して調整可能に改修したFizzBuzz2.shを作成する。(10点) [if文による制御]
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 | |
#for文によるFizzBuzz | |
if [ $1 -ge 0 -a $2 -ge 0 ]; then | |
for i in `seq $1 $2` #seq a b aからbまでループ | |
do | |
if [ `expr $i % 15` -eq 0 ]; then | |
echo "FizzBuzz " | |
elif [ `expr $i % 3` -eq 0 ]; then | |
echo "Fizz " | |
elif [ `expr $i % 5` -eq 0 ]; then | |
echo "Buzz" | |
else | |
echo "$i " | |
fi | |
done | |
else | |
echo "2つの非負数を引数にしてください。" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment