[ create a new paste ] login | about

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

C:
pasted 9 hours ago:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
main(){

    int a;

    for(a=1;a<101;a++){
        if(a%15==0){
            printf("fizzbuzz\n");
        }else if(a%5==0){
            printf("buzz\n");
        }else if(a%3==0){
            printf("fizz\n");
        }else{
            printf("%d\n",a);
        }
    }
    return 0;
}
view (18 lines, 100 lines of output)
pasted 9 hours ago:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <stdio.h>
main(){

    int a;

    for(a=1;a<101;a++){
        if(a%15==0){
            printf("fizzbuzz\n");
        }else if(a%5==0){
            printf("buzz\n");
            }else if(a%3==0){
                    printf("fizz\n");
                }else{
                    printf("%d\n",a);
                }
    }
    return 0;
}
view (18 lines, 100 lines of output)


C++:
pasted on Apr 18:
int main()
{
  for(int i = 1; i <= 100; i++)
  {
    if(i%3 == 0 && i%5 == 0)
    {
    cout <<"FizzBuzz\n";
    }
    else if(i%3 == 0)
    {
    cout <<"Fizz\n";
    }
    else if(i%5 == 0)
    {
    cout <<"Buzz\n";
    }
    else
    {
    cout <<i <<"\n";
    }
  }
}
view (22 lines, 100 lines of output)
pasted on Apr 7:
int main()
{
  for(int i = 1; i <= 100; i++)
  {
    if(i%3 == 0 && i%5 == 0)
    {
    cout <<"FizzBuzz\n";
    }
    else if(i%3 == 0)
    {
    cout <<"Fizz\n";
    }
    else if(i%5 == 0)
    {
    cout <<"Buzz\n";
    }
    else
    {
    cout <<i <<"\n";
    }
  }
}
view (22 lines, 100 lines of output)


Haskell:
pasted on Apr 25:
1
2
3
4
5
6
7
8
fizz :: Int -> String
fizz n | n `mod` 15 == 0  = "FizzBuzz"
       | n `mod` 3  == 0  = "Fizz"
       | n `mod` 5  == 0  = "Buzz"
       | otherwise        = show n
 
main :: IO()
main = mapM_ putStrLn $ map fizz [1..100]
view (8 lines, 100 lines of output)
pasted on Mar 20:
1
2
3
4
5
6
7
8
fizz :: Int -> String
fizz n | n `mod` 15 == 0  = "FizzBuzz"
       | n `mod` 3  == 0  = "Fizz"
       | n `mod` 5  == 0  = "Buzz"
       | otherwise        = show n
 
main :: IO()
main = mapM_ putStrLn $ map fizz [1..100]
view (8 lines, 100 lines of output)


Lua:
pasted on Mar 2:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function fizzbuzz(n)
    if n%15 == 0 then
        print("fizzbuzz")
    elseif n%5 == 0 then
        print("buzz")
    elseif n%3 == 0 then
        print("fizz")
    else
        print("" .. n)
    end
end

for i=1,100,1 do
    fizzbuzz(i)
end
view (15 lines, 100 lines of output)
pasted on Feb 14:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function fizzbuzz(n)
    if n%15 == 0 then
        print("fizzbuzz")
    elseif n%5 == 0 then
        print("buzz")
    elseif n%3 == 0 then
        print("fizz")
    else
        print("" .. n)
    end
end

for i=1,100,1 do
    fizzbuzz(i)
end
view (15 lines, 100 lines of output)


PHP:
clambercy - pasted on Dec 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php

for ($i = 1; $i <= 100; $i++) {
    $out = '';
    if ($i % 3 == 0) {
        $out = "Fizz";
    } 
    if ($i % 5 == 0) {
        $out .= "Buzz";
    }
    
    echo ($out ? $out : $i) . PHP_EOL;
}


?>
view (16 lines, 100 lines of output)
clambercy - pasted on Dec 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php

for ($i = 1; $i <= 100; $i++) {
    $out = '';
    if ($i % 3 == 0) {
        $out = "Fizz";
    } 
    if ($i % 5 == 0) {
        $out .= "Buzz";
    }
    if ($out == '') {
        $out = $i;
    } 
    echo ($out ? $out : $i) . PHP_EOL;
}


?>
view (18 lines, 100 lines of output)


Perl:
pasted on Apr 17:
1
print$_%15?$_%5?$_%3?$_:'Fizz':'Buzz':'FizzBuzz',"\n"for 1..100;
view (1 line, 100 lines of output)


Python:
pasted on Apr 21:
1
for x in range(100): print x%3/2*'Fizz'+x%5/4*'Buzz' or x+1
view (1 line, 100 lines of output)
pasted on Apr 21:
1
for x in range(1,101):print"fizz"[x%3*4::]+"buzz"[x%5*4::]or x
view (2 lines, 100 lines of output)


Ruby:
pasted on Mar 22:
1
2
3
4
5
6
7
8
9
10
11
(1..100).each do |n|
if n % 5 == 0 && n % 3 == 0
puts "FizzBuzz"
elsif n % 5 == 0
puts "Buzz"
elsif n % 3 == 0
puts "Fizz"
else
puts n
end 
end 
view (11 lines, 100 lines of output)
pasted on Mar 22:
1
2
3
4
5
6
7
8
9
10
11
(1..100).each do |i|
  if i % 5 == 0 and i % 3 == 0
    puts "FizzBuzz"
  elsif i % 5 == 0
    puts "Buzz"
  elsif i % 3 == 0
    puts "Fizz"
  else
    puts i 
  end 
end 
view (11 lines, 100 lines of output)