Skip to content
This repository
Newer
Older
100644 40 lines (36 sloc) 1.373 kb
877bc5fb »
2012-05-07 Initial Commit
1 /* FizzBuzz Solution
2 * by: Eric Gallager
3 * 5/6/12
4 *
5 * Problem: Write a program that prints the numbers from 1 to 100.
6 * But for multiples of 3 print "Fizz" instead of the number and for the multiples of five print "Buzz".
7 * For numbers which multiples of both three and five print "FizzBuzz".
8 *
9 */
10
11 #include <stdio.h>
12 #include <math.h>
13 #include <stdlib.h>
14 #include <limits.h>
15 #include <float.h> // I like including more headers than necessary, you never know when they might come in handy!
16 #ifdef __OBJC__
17 #include <dispatch/dispatch.h>
18 #endif
19
20 // I felt like using #defines because I could
21 #define Fizz 3
22 #define Buzz 5
23 #define FizzBuzz 15
24
25 int main (int number) { // I was using type "double" at first, but had to remove it once I switched from division to remainder (see below)
26 for (number = 1; number <= 100; number++) {
27 if (number % FizzBuzz == 0) { // using the "remainder" function instead of division because when I used division == 1, it only worked for the first time it hit a multiple of it
28 printf("FizzBuzz \n"); // putting the "FizzBuzz" statement first, because when I put it last, it would hit the "Fizz" conditional first and just print that instead
29 } else if (number % Fizz == 0) {
30 printf("Fizz \n");
31 } else if (number % Buzz == 0) {
32 printf("Buzz \n");
33 } else {
34 printf("%i \n", number);
35 }
36 }
37 return 0;
38 }
39 // newline \n
Something went wrong with that request. Please try again.