Skip to content

Instantly share code, notes, and snippets.

@jadudm
Created September 10, 2014 18:52
Show Gist options
  • Save jadudm/533e93bc649f29d84412 to your computer and use it in GitHub Desktop.
Save jadudm/533e93bc649f29d84412 to your computer and use it in GitHub Desktop.
FizzBuzz
/* A short FizzBuzz implementation, primarily for
demonstration of some of the features of C.
To compile this program, at the terminal, type:
gcc fizzbuzz.c
which will give you the executable "a.out".
To run it, type:
./a.out
You may want to CTRL-K to clear your terminal first, and
it is possible you may also want to increase the scrollback buffer.
Also, turn on AUTOSAVE. :)
*/
/* Includes */
#include <stdio.h>
/* Main */
/* main() must return an int. */
int main ()
{
int i;
for (i = 0 ; i < 1024 ; i += 1 )
{
/* C++
cout << i << eol?;
Python
print i
*/
if ((i % 3 == 0) && (i % 5 == 0)) {
printf("FizzBuzz\n");
} else if (i % 5 == 0) {
printf("Buzz\n");
} else if (i % 3 == 0) {
printf ("Fizz\n");
} else {
printf("%d\n", i);
}
}
/* Return 0; everything is JUST FINE. */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment