[ create a new paste ] login | about

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

C:
pasted on Aug 5:
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 Jul 19:
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 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)
pasted on Feb 13:
#include<iostream>

using namespace std;

int main()
{

for(int count = 1; count <= 100; ++count)
{
    if(count%3 == 0 and count%5 == 0)
    {
        printf("fizzbuzz\n");
    }
    else if(count%3 == 0)
    {
        printf("fizz\n");
    }
    else if(count%5 == 0)
    {
        printf("buzz\n");
    }    
    else
    {
        printf("%d\n", count);
    }

}


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


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)
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)


Python:
Jaqknife - pasted on Jul 12:
1
2
3
4
5
6
7
8
9
10
11
12
13
x=0

for i in range(1,101):

    x+=1
    if x%15 == 0:
        print ("FizzBuzz")
    elif x%3 == 0:
        print ("Fizz")
    elif x%5 == 0:
        print ("Buzz")
    else:
        print x
view (13 lines, 100 lines of output)
pasted on Jun 18:
1
2
3
4
5
6
7
8
9
10
11
12
13
x=0

for i in range(1,101):

    x+=1
    if x%15 == 0:
        print ("FizzBuzz")
    elif x%3 == 0:
        print ("Fizz")
    elif x%5 == 0:
        print ("Buzz")
    else:
        print x
view (13 lines, 100 lines of output)


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)