[ create a new paste ] login | about

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

C:
pasted yesterday:
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 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)
pasted on Jan 22:
sub the_results{ map{$_."\n"}@_}

sub of_looking_at{
    my @List_with_Fizz_and_Buzz;

    for my $original_number (@_){
        my $new_number = Append_Fizz_if_divisible_by_three ($original_number);
        $new_number .= Append_Buzz_if_divisible_by_five ($original_number);
        $new_number = $original_number unless $new_number;
        push @List_with_Fizz_and_Buzz, $new_number
    }
    return @List_with_Fizz_and_Buzz
}

sub a_list{ (1..100) }




print the_results of_looking_at a_list;




sub Append_Fizz_if_divisible_by_three{
    return "Fizz" unless $_[0]%3;''
}

sub Append_Buzz_if_divisible_by_five{
    return "Buzz" unless $_[0]%5;''
    
}
view (32 lines, 100 lines of output)


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