Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FizzBuzz

Name: VIPPER 2011-05-15 3:49

Write a program that prints the integers 1 - 100, but for every multiple of 3, print "Fizz" instead of the number, for every multiple of 5 print "Buzz", and for every multiple of both 3 and 5, print "FizzBuzz".


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
        for (int i = 1; i <= 100; i++) {
                if (i % 3 == 0 && i % 5 == 0)
                        puts("FizzBuzz");
                else if (i % 3 == 0)
                        puts("Fizz");
                else if (i % 5 == 0)
                        puts("Buzz");
                else
                        printf("%d\n", i);
        }
        return EXIT_SUCCESS;
}

Name: >>9 2011-05-15 8:29

Also this:

void fizzbuzz( int x ) {
        int n = 0;
        char *fizzbuff[] = { "%d\n", "Fizz\n", "Buzz\n", "FizzBuzz\n" };

        if( !(x%3) ) n++;
        if( !(x%5) ) n+=2;

        printf(fizzbuff[n], x);

        return;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List