[ create a new paste ] login | about

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

C:
pasted on Jan 22:
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 (25 lines, 100 lines of output)
pasted on Dec 28:
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 (25 lines, 100 lines of output)


C++:
Almg - pasted on Jan 17:
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main ()
{
stringstream ss;
for (int i = 1; i  < 101; i++)
{
ss.str(string ());
ss.clear ();
if (i % 3 == 0)
ss << "Fizz";
if (i%5 == 0)
ss << "Buzz";
if (ss.str() == "")
ss << i;
cout << ss.str() << endl;
}
return 0;
}
view (23 lines, 100 lines of output)
pasted on Jan 6:
#include <iostream>
#include <string>
using namespace std;

int main()
{
 for (int x = 1; x < 101; x++)
 {
 string output;
 if (x % 3 == 0)
 {
 output += "fizz";
 }
 if (x % 5 == 0)
 {
 output += "buzz";
 }
 if (output.empty())
 {
 cout << x << endl;
 }
 else
 {
 cout << output << endl;
 }
 }
}
view (27 lines, 100 lines of output)


Perl:
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)
pasted on Jan 2:
1
2
3
4
5
6
7
8
@a=(
 sub {print "FizzBuzz\n"},
 sub {print "Buzz\n"},
 sub {print "Fizz\n"},
 sub {print "$_[0]\n"}
);

$a[   ($_%3 != 0) + (2 * ($_%5 != 0))   ]->($_) for (1..100)
view (8 lines, 100 lines of output)


Python:
pasted on Jan 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# coding: utf-8

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 (15 lines, 100 lines of output)
pasted on Jan 19:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# coding: utf-8

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 (15 lines, 100 lines of output)