[ create a new paste ] login | about

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

C:
pasted on Sep 22:
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)
pasted on Aug 17:
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, 373 comments)


C++:
pasted on Aug 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>

int main() {
    for(int x = 1; x <= 100; x++) {        
        if(x % 15 == 0) {
            std::cout << "fizzbuzz\n";  
        }
        else if(x % 3 == 0) {
            std::cout << "fizz\n";
        }
        else if(x % 5 == 0) {
            std::cout << "buzz\n";
        }
        else {
            std::cout << x << std::endl;
        }
    }
    return 0;
}
view (19 lines, 100 lines of output, 3 comments)
pasted on Jul 16:
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, 3 comments)


Perl:
pasted on Jul 21:
1
2
3
4
5
6
7
8
9
10
@a=(
sub{print "FizzBuzz\n"},
sub{print "Buzz\n"},
sub{print "Fizz\n"},
sub {print "$_[0]\n"}
);



$a[   !!($_%3) + (2*!!($_%5))   ]->($_) for (1..100)
view (10 lines, 100 lines of output, 373 comments)
pasted on Jul 21:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
push @a, action ($_) for (1..100);

print map{$_->()."\n"}@a;

sub action{
   my $v = pop;

   sub {
      my $Narf;
      $Narf .= 'Fizz' unless $v%3;
      $Narf .= 'Buzz' unless $v%5;

      $Narf?$Narf:$v;
   }
}
view (15 lines, 100 lines of output, 3 comments)


Python:
pasted on Sep 18:
1
2
3
4
5
6
7
8
if __name__ == "__main__":
    for i in range(1,101):
        s = ""
        if i%3 == 0:
            s +="Fizz"
        if i%5 == 0:
            s += "Buzz"
        print(s if s else i)
view (8 lines, 100 lines of output)
pasted on Sep 18:
1
2
3
4
5
6
7
8
if __name__ == "__main__":
    for i in range(1,101):
        s = ""
        if i%3 == 0:
            s +="Fizz"
        if i%5 == 0:
            s += "Buzz"
        print(s if s else i)
view (8 lines, 100 lines of output, 373 comments)


Ruby:
pasted on Jun 28:
1
2
3
4
5
6
7
8
9
10
11
12
1.upto(100) do |x|
	if x % 3 == 0
		print "Fizz"
	end
	if x % 5 == 0
		print "Buzz"
	end
	if x % 3 != 0 && x % 5 != 0
		print x
	end
	print "\n"
end
view (12 lines, 100 lines of output, 3 comments)