typestar

FizzBuzz in C

The classic screening exercise for loops and conditionals.

void fizzbuzz(int n) {
    for (int i = 1; i <= n; i++) {
        if (i % 15 == 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);
    }
}

Keywords and builtins used here

The run, in numbers

Lines
12
Characters to type
198
Tokens
90
Three-star pace
85 tpm

At the three-star pace of 85 tokens a minute, this run takes about 64 seconds.

Type this snippet

Step 7 of 7 in Operators & flow, step 14 of 35 in Language basics.

← Previous Next →

FizzBuzz in other languages