[ create a new paste ] login | about

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

C:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>

int main(void){
int i=0;
for(i=1;i<=100;i++){
    if(i%15==0){
        printf("FizzBuzz\n");
    }   
    else if(i%5==0){
        printf("Buzz\n");
    }
    else if(i%3==0){
        printf("Fizz\n");
    }
    else
        printf("%i\n",i);
    
}

return 0;
}
view (21 lines, 100 lines of output)
pasted on Jun 17:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
int main()
{

int i,j,k;
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 (19 lines, 100 lines of output)


C++:
pasted on Jun 13:
#include <iostream>

int main(int argc, char* argv[]) 
{
	// Print number s from 1 to 100
	for(int i=1; i<101; ++i) {
		
		if(i % 3 ==0) {
			std::cout << "Fizz";
			if(i % 5 == 0)
			std::cout << "Buzz";
		}
		else if(i % 5 ==0)
			std::cout << "Buzz";
		else
			std::cout << i;

		std::cout << std::endl;	
		
	}


}
view (23 lines, 100 lines of output)
pasted on Jun 13:
#include <iostream>

int main(int argc, char* argv[]) 
{
	// Print number s from 1 to 100
	for(int i=1; i<101; ++i) {
		
		if(i % 3 ==0) {
			std::cout << "Fizz";
			if(i % 5 == 0)
			std::cout << "Buzz";
		}
		else if(i % 5 ==0)
			std::cout << "Buzz";
		else
			std::cout << i;

		std::cout << std::endl;	
		
	}


}
view (23 lines, 100 lines of output)


D:
pasted on Mar 23:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import std.stdio;

void main()
{
for (int i = 1; i <= 100; i++) {
bool special = false;
if (i % 3 == 0) {
special = true;
writef("Fizz");
}
if (i % 5 == 0) {
special = true;
writef("Buzz");
}
if (!special) writef("%d", i);
writef("\n");
}
}
view (18 lines, 100 lines of output)


Haskell:
pasted on Jun 15:
1
2
3
4
5
6
7
8
9
10
11
12
import Control.Monad.Writer

fb = const "fizzbuzz"
f  = const "fizz"
b  = const "buzz"

s :: Show b => b -> String
s  = show

fns :: Show b => [b -> String]
fns  = [fb, s, s, f, s, b, f, s, s, f, b, s, f, s, s]
main = mapM_ (putStrLn . ((fns !!) =<< (`mod` 15))) [1..100]
view (12 lines, 100 lines of output)
pasted on Jun 15:
1
2
3
4
5
6
7
8
9
10
11
import Control.Monad.Writer

fb = const "fizzbuzz"
f  = const "fizz"
b  = const "buzz"

s x = show x--s  = show

fns :: Show b => [b -> String]
fns  = [fb, s, s, f, s, b, f, s, s, f, b, s, f, s, s]
main = mapM_ (putStrLn . ((fns !!) =<< (`mod` 15))) [1..100]
view (11 lines, 100 lines of output)


Lua:
pasted on May 19:
1
for i=1,100 do print(i%15==0 and"FizzBuzz"or(i%5==0 and"Buzz"or(i%3==0 and"Fizz"or i)))end
view (1 line, 100 lines of output)
AgentE382 - pasted on May 4:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
--[[Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz”.]]

for i = 1,100 do
    normal = true
    if i % 3 == 0 then
        io.write("Fizz")
        normal = false
    end
    if i % 5 == 0 then
        io.write("Buzz")
        normal = false
    end
    if normal then
        io.write(i)
    end
    io.write("\n")
end
view (17 lines, 100 lines of output)


PHP:
pasted yesterday:
1
2
3
4
5
6
7
8
9
10
11
<?php
$flag = 0;
for($count = 1; $count <= 100; $count++)
{
    if($count%3 == 0){$flag = 1;echo "Fizz";}
    if($count%5 == 0){$flag = 1;echo "Buzz";}
    if(!$flag){echo $count;}
    echo "\n";
    $flag = 0;
}
?>
view (11 lines, 100 lines of output)
pasted yesterday:
1
2
3
4
5
6
7
8
9
<?php
for($count = 1; $count <= 100; $count++)
{
    if($count%3 == 0 && $count%5 == 0){echo "FizzBuzz\n";}
    else if($count%3 == 0){echo "Fizz\n";}
    else if($count%5 == 0){echo "Buzz\n";}
    else{echo $count."\n";}
}
?>
view (9 lines, 100 lines of output)


Perl:
pasted on May 17:
1
$i=1;while($i<=100){print($i%3 eq 0 && $i%5 eq 0?fizzbuzz:($i%3 eq 0?fizz:($i%5 eq 0?buzz:$i)),"\n");$i++}
view (1 line, 100 lines of output)
pasted on May 17:
1
$i=1;while($i<=100){if($i%3 eq 0 && $i%5 eq 0){print"fizzbuzz\n";}elsif($i%3 eq 0){print"fizz\n";}elsif($i%5 eq 0){print"buzz\n";}else{print($i,"\n");}$i++;}
view (1 line, 100 lines of output)


Python:
pasted on Jun 17:
1
print '\n'.join(['Fizz'*(not i%3) + 'Buzz'*(not i%5) or str(i) for i in range(1, 101)])
view (1 line, 100 lines of output)
pasted on Jun 14:
1
print '\n'.join(['Fizz'*(not i%3) + 'Buzz'*(not i%5) or str(i) for i in range(1, 101)])
view (1 line, 100 lines of output)


Ruby:
pasted on Jun 12:
1
2
3
4
5
6
1.upto(100) { |x|
    print "fizz" if x % 3 == 0
    print "buzz" if x % 5 == 0 
    print x      unless (x % 3 == 0) or (x % 5 == 0)
    puts ""
}
view (6 lines, 100 lines of output)
pasted on Jun 7:
1
2
3
4
5
6
7
8
9
10
11
1.upto(100) do |n|
  if n % 3 == 0 && n % 5 == 0
    puts "FizzBuzz"
  elsif n % 3 == 0
    puts "Fizz"
  elsif n % 5 == 0
    puts "Buzz"
  else
    puts n
  end
end
view (11 lines, 100 lines of output)


Scheme:
pasted on Mar 3:
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 Feb 19:
1
(do((n 1 (+ 1 n)))((> n 100))(printf "~v\n" (cadr(assv(gcd 15 n) `((1,n)(3 fizz)(5 buzz)(15 fizzbuzz))))))
view (1 line, 100 lines of output)