I created it as a small story of Bash programming. I am writing an article at a rapid pace for some reason. By the way, this is the third installment.
For FizzBuzz, please check here. Count up from 1
--Display "Fizz" when divisible by 3 --Display "Buzz" when divisible by 5 --Display "FizzBuzz" when it is divisible by both
And so on.
#!/bin/bash
echo -n "Please input number => "
read num
for i in $(seq 1 ${num})
do
if (( $i % 3 == 0 && $i % 5 == 0 ))
then
echo "FizzBuzz"
else if (( $i % 3 == 0))
then
echo "Fizz"
else if (( $i % 5 == 0 ))
then
echo "Buzz"
else
echo $i
fi
fi
fi
sleep 1
done
$ ./fizzbuzz.sh
Please input number => 15
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
You can make it by applying a program that becomes aho when there are multiples of 3 and a character string of 3.
By creating this program
--Algorithm --Conditional expression --Conditional operator --read command
I understand.
Recommended Posts