FizzBuzz - a game played by childern in school, esp in UK.
In this game a group of children sit around in a group and say each number in sequence,
except if the number is a multiple of three (in which case they say “Fizz”) or five
(when they say “Buzz”). If a number is a multiple of both three and five they have
to say “Fizz-Buzz”.
--**MSSQL
with tmp(n) as (select 1 union all select n+1 from tmp where n<100)
select
case
when n%3=0 and n%5=0 then 'FizzBuzz'
when n%3=0 then 'Fizz'
when n%5=0 then 'Buzz'
else cast(n as char)
end
from tmp;
--**DB2
with tmp(n) as (values 1 union all select n+1 from tmp where n<100)
select
case
when mod(n,3)=0 and mod(n,5)=0 then 'FizzBuzz'
when mod(n,3)=0 then 'Fizz'
when mod(n,5)=0 then 'Buzz'
else cast(n as char(2))
end
from tmp;
--**ORACLE
with tmp(n) as (select 1 from dual union all select n+1 from tmp where n<100)
select
case
when mod(n,3)=0 and mod(n,5)=0 then cast('FizzBuzz' as char(10))
when mod(n,3)=0 then cast('Fizz' as char(10))
when mod(n,5)=0 then cast('Buzz' as char(10))
else cast(n as char(10))
end
from tmp ;
--**MSDOS - Windows batch script
Setlocal EnableDelayedExpansion
for /l %%x in (1,1,100) do ( set /a "fizz = %%x %%3" & set /a "buzz = %%x %%5"
if !fizz! equ 0 if !buzz! equ 0 echo.FizzBuzz
if !fizz! equ 0 if !buzz! neq 0 echo.Fizz
if !fizz! neq 0 if !buzz! equ 0 echo.Buzz
if !fizz! neq 0 if !buzz! neq 0 echo.%%x
)
Endlocal
--**Perl
for my $num (1 .. 100) {
if ($num%3==0 && $num%5==0){ print "FizzBuzz\n";}
if ($num%3==0 && $num%5!=0){ print "Fizz\n";}
if ($num%3!=0 && $num%5==0){ print "Buzz\n";}
if ($num%3!=0 && $num%5!=0){ print $num,"\n";}
}
--**Bash
for (( num=1;num<=100;num++));
do
if [ $((num % 3)) -eq 0 ] && [ $((num%5)) -eq 0 ]; then echo 'FizzBuzz'
elif [ $((num % 3)) -eq 0 ] && [ $((num%5)) -ne 0 ]; then echo 'Fizz'
elif [ $((num % 3)) -ne 0 ] && [ $((num%5)) -eq 0 ]; then echo 'Buzz'
else echo $num
fi
done
--**VBScript
for x = 1 to 100
if (x Mod 3 = 0 and x Mod 5 = 0) then wscript.echo "FizzBuzz"
if (x Mod 3 <> 0 and x Mod 5 = 0) then wscript.echo "Buzz"
if (x Mod 3 = 0 and x Mod 5 <> 0) then wscript.echo "Fizz"
if (x Mod 3 <> 0 and x Mod 5 <> 0) then wscript.echo x
next
for x = 1 to 100
if (x Mod 3 = 0 and x Mod 5 = 0) then document.write "FizzBuzz<br>"
if (x Mod 3 <> 0 and x Mod 5 = 0) then document.write "Buzz<br>"
if (x Mod 3 = 0 and x Mod 5 <> 0) then document.write "Fizz<br>"
if (x Mod 3 <> 0 and x Mod 5 <> 0) then document.write x & "<br>"
next