[ create a new paste ] login | about

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

C:
fargus3000 - pasted on Jul 26:
#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)


Lua:
pasted on Sep 1:
1
2
3
4
5
6
7
8
9
for i = 1, 100 do
    result = (i % 3 == 0 and "Fizz" or "")..(i % 5 == 0 and "Buzz" or "")

    if result == "" then
        result = i
    end

    print(result)
end
view (9 lines, 100 lines of output)
pasted on Sep 1:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
for i = 1, 100 do
    result = ""
    if i % 3 == 0 then
        result = result.."Fizz"
    end

    if i % 5 == 0 then
        result = result.."Buzz"
    end

    if result == "" then
        result = i
    end

    print(result)
end
view (16 lines, 100 lines of output)


Python:
pasted on Apr 1:
1
2
3
4
5
6
7
8
9
10
for i in range(1,101):
    txt = ''
    if i%3==0:
        txt += 'Fizz'
    if i%5==0:
        txt += 'Buzz'
    if txt == '':
        print(i)
    else:
        print(txt)
view (11 lines, 100 lines of output)
pasted on Apr 1:
1
2
3
4
5
6
7
8
9
for i in range(1,101):
    if i%15==0:
        print('FizzBuzz')
    elif i%5==0:
        print("Buzz")
    elif i%3==0:
        print('Fizz')
    else:
        print(i)
view (9 lines, 100 lines of output)