[ create a new paste ] login | about

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

C:
pasted on Dec 29:
#include <stdio.h>
#include <stdbool.h>

//void fizzbuzzя() {
//    int x = 0;
//    for(x = 1; x <= 100; ++x){
//    printf("%d ", x);
//    if(x%3 == 0) printf("Fizz");
//    if(x%5 == 0) printf("Buzz");
//    printf("\n");
//} 
//}


void fizzbuzz() {
    int y = 0;
    for(y = 1; y < 101; ++y){
        if(y%15 == 0) printf("FizzBuzz\n");
        else if(y%3 == 0) printf("Fizz\n");
        else if(y%5 == 0) printf("Buzz\n");
        else printf("%d\n", y);
    }
}

int main() {

   fizzbuzz(); 
   return 0;
}
view (29 lines, 100 lines of output)
pasted on Dec 29:
#include <stdio.h>
#include <stdbool.h>

//void fizzbuzzя() {
//    int x = 0;
//    for(x = 1; x <= 100; ++x){
//    printf("%d ", x);
//    if(x%3 == 0) printf("Fizz");
//    if(x%5 == 0) printf("Buzz");
//    printf("\n");
//} 
//}


void fizzbuzz() {
    int y = 0;
    for(y = 1; y < 101; ++y){
        if(y%15 == 0) printf("FizzBuzz\n");
        else if(y%3 == 0) printf("Fizz\n");
        else if(y%5 == 0) printf("Buzz\n");
        else printf("%d\n", y);
    }
}

int main() {

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


C++:
pasted on Dec 9:
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)
pasted on Nov 27:
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)


PHP:
LemmyRock - pasted on Nov 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php 
for ($i=1;$i<=100;$i++) {

    if ($i % 3 == 0 && $i %  5 == 0) {
        echo "FizzBuzz\n";
        continue;
    }

    if ($i % 3 == 0) {
        echo "Fizz\n";
    } else if ($i % 5 == 0) {
        echo "Buzz\n"; 
    } else {
        echo "$i\n";
    }
    

}
view (18 lines, 100 lines of output)
pasted on Oct 5:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php 
for ($i=1;$i<=100;$i++) {

    if ($i % 3 == 0 && $i %  5 == 0) {
        echo "FizzBuzz\n";
        continue;
    }

    if ($i % 3 == 0) {
        echo "Fizz\n";
    } else if ($i % 5 == 0) {
        echo "Buzz\n"; 
    } else {
        echo "$i\n";
    }
    

}
view (18 lines, 100 lines of output)


Python:
pasted on Jan 3:
1
2
3
4
5
6
7
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 (7 lines, 100 lines of output)
pasted on Dec 31:
1
2
3
4
5
6
7
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 (7 lines, 100 lines of output)


Ruby:
pasted on Nov 12:
1
puts((1..100).map{|n|a=n%3==0;b=n%5==0;((a)?%?Fizz?:%::)+((b)?%?Buzz?:%::)+((a||b)?%??:n.to_s)})
view (1 line, 100 lines of output)
pasted on Nov 12:
1
puts((1..100).map{|n|a=n%3==0;b=n%5==0;(a)?((b)?%?FizzBuzz?:%:Fizz:):((b)?%?Buzz?:n)})
view (1 line, 100 lines of output)