[ create a new paste ] login | about

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

C:
pasted yesterday:
#include <stdio.h>

int main(void) {
    int i = 0;

    for(i = 1; i < 101; i++) {
        if(i % 3 != 0 && i % 5 != 0) {
            printf("%d", i);
        }
        else {
            if(i % 3 == 0) {
                printf("fizz");
            }
        
            if(i % 5 == 0) {
                printf("buzz");
            }
        }

        printf("\n");
    }

    return 0;
}
view (24 lines, 100 lines of output)
pasted on Aug 20:
#include <stdio.h>

int main(void) {
    int i = 0;

    for(i = 1; i < 101; i++) {
        if(i % 3 != 0 && i % 5 != 0) {
            printf("%d", i);
        }
        else {
            if(i % 3 == 0) {
                printf("fizz");
            }
        
            if(i % 5 == 0) {
                printf("buzz");
            }
        }

        printf("\n");
    }

    return 0;
}
view (24 lines, 100 lines of output)


C++:
jouda9 - pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
int main()
{
int i;
for(i=1;i<=100;i++)
{
    if(i%3==0 && i%5==0)
        cout<<"FizzBuzz"<<endl;
    else if(i%3==0)
        cout<<"Fizz"<<endl;
    else if(i%5==0)
        cout<<"Buzz"<<endl;
    else
        cout<<i<<endl;
}
return 0;
}
view (18 lines, 100 lines of output)
jouda9 - pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
using namespace std;
int main()
{
int i;
for(i=1;i<=100;i++)
{
    if(i%3==0 && i%5==0)
        cout<<"FizzBuzz"<<endl;
    else if(i%3==0)
        cout<<"Fizz"<<endl;
    else if(i%5==0)
        cout<<"Buzz"<<endl;
    else
        cout<<i<<endl;
}
return 0;
}
view (18 lines, 100 lines of output)


Haskell:
pasted 12 hours ago:
1
2
3
4
5
6
7
8
main = do
  putStr . unlines $ map fizzbuzz [1..100]

fizzbuzz n
  | mod n 15 == 0 = "Fizzbuzz"
  | mod n 3 == 0 = "Fizz"
  | mod n 5 == 0 = "Buzz"
  | otherwise = show n
view (8 lines, 100 lines of output)
pasted 12 hours ago:
1
2
3
4
5
6
7
8
main = do
  putStr . unlines $ map fizzbuzz' [1..100]

fizzbuzz' n
  | mod n 15 == 0 = "Fizzbuzz"
  | mod n 3 == 0 = "Fizz"
  | mod n 5 == 0 = "Buzz"
  | otherwise = show n
view (8 lines, 100 lines of output)


Lua:
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)
pasted on Aug 19:
1
for i=1,100 do print(i%15<1 and"FizzBuzz"or i%3<1 and"Fizz"or i%5<1 and"Buzz"or i)end
view (1 line, 100 lines of output)


PHP:
pasted yesterday:
1
2
3
4
5
6
7
8
9
<?php for ($x=1;$x<=100;$x++){   
  $fizz = $x % 3;  
  $buzz = $x % 5;
    if($fizz==0 && $buzz==0){  
                 echo "FizzBuzz";     }
              elseif($fizz==0){  echo "Fizz";    }
                      elseif($buzz==0){    echo "Buzz";   }
                             else{      echo $x;     }   
  echo "\n"; }
view (9 lines, 100 lines of output)
pasted yesterday:
1
<?php for ($x=1;$x<=100;$x++){     $fizz = $x % 3;    $buzz = $x % 5;    if($fizz==0 && $buzz==0){   echo "FizzBuzz";     }elseif($fizz==0){  echo "Fizz";    }elseif($buzz==0){    echo "Buzz";   }else{      echo $x;     }    echo "\n"; }
view (1 line, 100 lines of output)


Perl:
pasted on May 29:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
for ($i=1; $i <= 100; $i++) {
    if (($i%3 == 0) and ($i%5 == 0)){
        print ("FizzBuzz\n");
    }
    elsif ($i%3 == 0){
        print ("Fizz\n");
    }
    elsif ($i%5 == 0){
        print ("Buzz\n");
    }
    else{
        print ("$i\n");
    }
}
view (14 lines, 100 lines of output)
pasted on May 22:
1
print 'Fizz'x!($_ % 3) . 'Buzz'x!($_ % 5) || $_, "\n" for 1 .. 100;
view (1 line, 100 lines of output)


Python:
pasted on Aug 20:
1
2
3
4
5
6
7
8
9
10
11
12
def fizzbuzz(number):
        if number % 3 == 0 and number % 5 == 0:
                return 'FizzBuzz'
        elif number % 3 == 0:
                return 'Fizz'
        elif number % 5 == 0:
                return 'Buzz'
        else:
                return number

for number in range(1,101):
        print fizzbuzz(number)
view (12 lines, 100 lines of output)
pasted on Aug 17:
1
2
3
4
5
6
7
8
9
10
11
12
def fizzbuzz(number):
        if number % 3 == 0 and number % 5 == 0:
                return 'FizzBuzz'
        elif number % 3 == 0:
                return 'Fizz'
        elif number % 5 == 0:
                return 'Buzz'
        else:
                return number

for number in range(1,101):
        print fizzbuzz(number)
view (12 lines, 100 lines of output)


Ruby:
pasted on Aug 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
x = 1
100.times do
	#starting from 1 repeat this process 100 times
	if x % 3 == 0 then puts x % 5 == 0 ? "fizzbuzz" : "fizz" end
		#if the number is divisible by 3 then see if it is also divisible by 5
		#divisible by both output fizzbuzz, else divisible only by 3 output fizz   	
	if x % 5 == 0 && x % 3 != 0 then puts "buzz" end
		#if the number is divisible by 5 but not 3 then output buzz
	puts x if x % 5 != 0 && x % 3 != 0
		#if the number is neither divisible by 3 nor 5 then output the number
   	x += 1
   		#increment
end
view (13 lines, 100 lines of output)
pasted on Aug 19:
1
2
3
4
5
6
7
x = 1
100.times do
	if x % 3 == 0 then puts x % 5 == 0 ? "fizzbuzz" : "fizz" end   	
	if x % 5 == 0 && x % 3 != 0 then puts "buzz" end
	puts x if x % 5 != 0 && x % 3 != 0
   	x += 1
end
view (7 lines, 100 lines of output)


Scheme:
pasted on May 30:
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)