[ create a new paste ] login | about

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

C:
pasted on Jan 23:
#include <stdio.h>

int main() {
    
    int i;
    for (i = 1; i <= 100; i++) {
        
        if (i % 3 == 0 && i % 5 == 0) {
            printf("FizzBuzz\n");
        }
        else if (i % 5 == 0) {
            printf("Buzz\n");
        }
        else if (i % 3 == 0) {
            printf("Fizz\n");
        }
        else
            printf("%d\n", i);
        
    }
    
    return 0;
}
view (23 lines, 100 lines of output)
pasted on Jan 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    #include <stdio.h>
     
    int main()
    {
    int i;
    for(i=1;i<=100;i++)
    {
    if(i%3==0&&i%5==0)
    printf("FizzBuzz\n");
    else if(i%3==0)
    printf("Fizz\n");
    else if(i%5==0)
    printf("Buzz\n");
    else
    printf("%d\n",i);
    }
    return 0;
    }
view (18 lines, 100 lines of output)


C++:
pasted on Jan 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
 
int main()
{
    int i, f = 2, b = 4; 
 
    for ( i = 1 ; i <= 100 ; ++i, --f, --b )
    {
        if ( f && b ) { std::cout << i;             }
        if ( !f )     { std::cout << "Fizz"; f = 3; }
        if ( !b )     { std::cout << "Buzz"; b = 5; }
        std::cout << std::endl;
    }
 
    return 0;
}
view (16 lines, 100 lines of output)
pasted on Jan 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
 
int main()
{
    int i, f = 2, b = 4; 
 
    for ( i = 1 ; i <= 100 ; ++i, --f, --b )
    {
        if ( f && b ) { std::cout << i;             }
        if ( !f )     { std::cout << "Fizz"; f = 3; }
        if ( !b )     { std::cout << "Buzz"; b = 5; }
        std::cout << std::endl;
    }
 
    return 0;
}
view (16 lines, 100 lines of output)


Haskell:
pasted on Dec 21:
1
main = mapM_ putStrLn $ map (\x -> if mod x 15 == 0 then "FizzBuzz" else if mod x 3 == 0 then "Fizz" else if mod x 5 == 0 then "Buzz" else show x) [1..100]
view (1 line, 100 lines of output)
pasted on Dec 16:
1
main = putStr . unlines $ map (\x -> if mod x 15 == 0 then "FizzBuzz" else if mod x 5 == 0 then "Buzz" else if mod x 3 == 0 then "Fizz" else show x) [1..100]
view (1 line, 100 lines of output)


Lua:
pasted on Nov 8:
1
2
3
4
5
6
7
8
9
10
11
for i=1, 100 do
	if i % 3 == 0 and i % 5 == 0 then
		print("Fizzbuzz")
	elseif i % 3 == 0 then
		print("Fizz")
	elseif i % 5 == 0 then
		print("Buzz")
	else
		print(i)
	end
end
view (11 lines, 100 lines of output)
pasted on Aug 19:
print([[
1
2
Fizz
4
Buzz
Fizz
7
8
Fizz
Buzz
11
Fizz
13
14
FizzBuzz
16
17
Fizz
19
Buzz
Fizz
22
23
Fizz
Buzz
26
Fizz
28
29
FizzBuzz
31
32
Fizz
34
Buzz
Fizz
37
38
Fizz
Buzz
41
Fizz
43
44
FizzBuzz
46
47
Fizz
49
Buzz
Fizz
52
53
Fizz
Buzz
56
Fizz
58
59
FizzBuzz
61
62
Fizz
64
Buzz
Fizz
67
68
Fizz
Buzz
71
Fizz
73
74
FizzBuzz
76
77
Fizz
79
Buzz
Fizz
82
83
Fizz
Buzz
86
Fizz
88
89
FizzBuzz
91
92
Fizz
94
Buzz
Fizz
97
98
Fizz
Buzz
]])
view (102 lines, 101 lines of output)


OCaml:
pasted on Oct 24:
1
2
3
4
5
6
7
8
9
10
11
let fizzbuzz index =
  match index mod 3, index mod 5 with
    0, 0 -> "FizzBuzz"
  | 0, _ -> "Fizz"
  | _, 0 -> "Buzz"
  | _    -> string_of_int index
 
let _ =
  for index = 1 to 100 do 
    print_endline (fizzbuzz index) 
  done
view (11 lines, 100 lines of output)
pasted on Oct 24:
1
2
3
4
5
6
7
8
9
let fizzbuzz index =
  match index mod 3, index mod 5 with
    0, 0 -> "FizzBuzz"
  | 0, _ -> "Fizz"
  | _, 0 -> "Buzz"
  | _    -> string_of_int index
 
let _ =
  for index = 1 to 100 do print_endline (fizzbuzz index) done
view (9 lines, 100 lines of output)


PHP:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
for ($i=1; $i<=100; $i++) {
    if (($i % 15) == 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 (13 lines, 100 lines of output)
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
for ($i=1; $i<=100; $i++) {
    if (($i % 15) == 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 (13 lines, 100 lines of output)


Perl:
pasted on Dec 24:
1
2
3
4
5
6
7
8
9
10
11
for ($i = 1; $i < 101; $i++) {
    if ($i % 15 < 1) {
        print "FizzBuzz\n";
    } elsif ($i % 3 < 1) {
        print "Fizz\n";
    } elsif ($i % 5 < 1) {
        print "Buzz\n";
    } else {
        print "$i\n";
    }
}
view (11 lines, 100 lines of output)
pasted on Dec 13:
1
2
3
4
5
6
7
8
9
10
11
12
#!/usr/bin/perl
for ($i = 1; $i < 101; $i++) {
    if ($i % 15 < 1) {
        print "FizzBuzz\n";
    } elsif ($i % 3 < 1) {
        print "Fizz\n";
    } elsif ($i % 5 < 1) {
        print "Buzz\n";
    } else {
        print "$i\n";
    }
}
view (12 lines, 100 lines of output)


Python:
pasted on Jan 1:
1
2
3
4
5
6
7
8
9
for theNumber in range(1, 101):
    if theNumber % 3 == 0 and theNumber % 5 == 0:
        print("FizzBuzz")
    elif theNumber % 5 == 0:
        print("Buzz")
    elif theNumber % 3 == 0:
        print("Fizz")
    else:
        print(theNumber)
view (9 lines, 100 lines of output)
RedMage1993 - pasted on Dec 24:
1
2
3
4
5
6
7
8
9
for theNumber in range(1, 101):
    if theNumber % 3 == 0 and theNumber % 5 == 0:
        print("FizzBuzz")
    elif theNumber % 5 == 0:
        print("Buzz")
    elif theNumber % 3 == 0:
        print("Fizz")
    else:
        print(theNumber)
view (9 lines, 100 lines of output)


Ruby:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
for num in 1..100 do
  if num % 15 == 0
    puts "FizzBuzz"
  elsif num % 5 == 0
    puts "Buzz"
  elsif num % 3 == 0
    puts "Fizz"
  else
    puts num
  end
end
view (11 lines, 100 lines of output)
pasted on Jan 24:
1
2
3
4
5
6
7
8
9
10
  for i in 1..100
            if i%3 == 0 && i%5 == 0
                puts "FizzBuzz"
                  elsif i%3 == 0
                puts "Fizz"
                  elsif i%5 == 0
                puts "Buzz"
                  else puts i
            end
        end
view (10 lines, 100 lines of output)


Scheme:
pasted on Jan 19:
1
2
3
4
5
6
7
8
(do ((i 1 (+ i 1)))
    ((> i 100))
    (display
      (cond ((= 0 (modulo i 15)) "FizzBuzz")
            ((= 0 (modulo i 3))  "Fizz")
            ((= 0 (modulo i 5))  "Buzz")
            (else                i)))
    (newline))
view (8 lines, 100 lines of output)
pasted on Jan 2:
1
2
3
4
5
6
7
8
(do ((i 1 (+ i 1)))
    ((> i 100))
    (display
      (cond ((= 0 (modulo i 15)) "FizzBuzz")
            ((= 0 (modulo i 3))  "Fizz")
            ((= 0 (modulo i 5))  "Buzz")
            (else                i)))
    (newline))
view (8 lines, 100 lines of output)