[ create a new paste ] login | about

Recent implementations of FizzBuzz, in:
[ C | C++ | Haskell | PHP | Perl | Python | Ruby ]

C:
pasted on Feb 4:
1
2
3
4
5
6
7
8
9
void main (void)
{
 int i;
 for (i=1; i<=100; i++)
 {
    (0==i%3 && 0==i%5) ?  printf("FizzBuzz\n") : 0==i%3 ? printf("Fizz\n") : 0==i%5 ? printf("Buzz\n") : printf("%d\n",i); 
        
 } 
}
view (9 lines, 100 lines of output)
pasted on Feb 1:
1
2
3
4
5
6
7
8
9
void main (void)
{
 int i;
 for (i=1; i<=100; i++)
 {
    (0==i%3 && 0==i%5) ?  printf("FizzBuzz\n") : 0==i%3 ? printf("Fizz\n") : 0==i%5 ? printf("Buzz\n") : printf("%d\n",i); 
        
 } 
}
view (9 lines, 100 lines of output)


C++:
pasted on Feb 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
    for (int i=1; i<=100; i++)
    {
        if (i%3 == 0)
            cout << "Fizz";
        if (i%5 == 0)
            cout << "Buzz";
        if (i%3 != 0 && i%5 != 0)
            cout << i;
        cout << "\n";
    }
    return 0;
}
view (14 lines, 100 lines of output)
pasted on Feb 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
    for (int i=1; i<=100; i++)
    {
        if (i%3 == 0)
            cout << "Fizz";
        if (i%5 == 0)
            cout << "Buzz";
        if (i%3 != 0 && i%5 != 0)
            cout << i;
        cout << "\n";
    }
    return 0;
}
view (14 lines, 100 lines of output)


Haskell:
pasted on Jan 13:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Main where

main :: IO ()
main = mapM_ (putStrLn . (fizzify 3 5)) [1..100]

fizzify :: Int -> Int -> Int -> String
fizzify a b n
    | isA && isB = "FizzBuzz"
    | isA        = "Fizz"
    | isB        = "Buzz"
    | otherwise  = show n
  where
    isA = n `mod` a == 0
    isB = n `mod` b == 0
view (14 lines, 100 lines of output)
pasted on Dec 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
module Main where

main :: IO ()
main = mapM_ (putStrLn . (fizzify 3 5)) [1..100]

fizzify :: Int -> Int -> Int -> String
fizzify a b n
    | isA && isB = "FizzBuzz"
    | isA        = "Fizz"
    | isB        = "Buzz"
    | otherwise  = show n
  where
    isA = n `mod` a == 0
    isB = n `mod` b == 0
view (14 lines, 100 lines of output)


PHP:
pasted on Jan 22:
1
<?php for($i = 1; $i <= 100; $i++){ if($i % 3 == 0 && $i % 5 == 0){ echo "FizzBuzz\n"; }else if($i % 3 == 0){ echo "Fizz\n"; }else if($i % 5 == 0){ echo "Buzz\n"; }else{ echo $i."\n"; } } ?>
view (1 line, 100 lines of output)
pasted on Dec 27:
1
<?php for($i = 1; $i <= 100; $i++){ if($i % 3 == 0 && $i % 5 == 0){ echo "FizzBuzz\n"; }else if($i % 3 == 0){ echo "Fizz\n"; }else if($i % 5 == 0){ echo "Buzz\n"; }else{ echo $i."\n"; } } ?>
view (1 line, 100 lines of output)


Perl:
pasted on Nov 20:
1
printf "%s\n", $_%15 ? $_%3 ? $_%5 ? $_ : "Buzz" : "Fizz" : "FizzBuzz" foreach(1..100);
view (1 line, 100 lines of output)
pasted on Oct 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
for $i (1..100)
{
   $message="";
   if($i%3==0)
   {
       $message.="Fizz";
   }
   if($i%5==0)
   {
       $message.="Buzz";
   }
   if($message eq "")
   {
       $message=$i;
   }
   print $message."\n";
}
view (17 lines, 100 lines of output)


Python:
pasted on Jan 21:
1
2
3
4
5
6
7
8
9
for num in xrange(1, 101):
  if (num%3 == 0) and (num%5 == 0):
    print ("FizzBuzz");
  elif ((num % 3) == 0):
    print ("Fizz");
  elif ((num % 5) == 0):
    print ("Buzz");
  else :
    print num;
view (9 lines, 100 lines of output)
pasted on Jan 21:
1
2
3
4
5
6
7
8
9
for num in xrange(1, 101):
  if (num%3 == 0) and (num%5 == 0):
    print ("FizzBuzz");
  elif ((num % 3) == 0):
    print ("Fizz");
  elif ((num % 5) == 0):
    print ("Buzz");
  else :
    print num;
view (9 lines, 100 lines of output)


Ruby:
pasted on Jan 15:
1
1.upto(100){|i,x|i%3<1&&x=:Fizz;puts i%5<1?"#{x}Buzz":x||i}
view (1 line, 100 lines of output)
pasted on Jan 15:
1
1.upto(100){|i|puts i%15<1?"FizzBuzz":i%3<1?"Fizz":i%5<1?"Buzz":i}
view (1 line, 100 lines of output)