[ create a new paste ] login | about

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

C:
pasted on Jun 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 Apr 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)


C++:
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)
pasted on Jan 30:
#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 Jun 30:
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)
pasted on Jun 1:
1
2
3
4
5
6
print
    map{$_."\n"}
    map{(/\d/ and !($_%5))?'Buzz':$_}
    map{(/\d/ and !($_%3))?'Fizz':$_}
    map{!($_%3 or $_%5)?'FizzBuzz': $_}
    (1..100)
view (7 lines, 100 lines of output)


Python:
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)
pasted on Apr 21:
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)