fizzbuzz.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /* Copyright © 2015, 2018 Jeffrey Cliff
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or (at
  6. * your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  15. */
  16. #include "stdio.h"
  17. void fizzbizz();
  18. // dummy driver function to actually get it execute.
  19. int main()
  20. {
  21. fizzbizz();
  22. }
  23. // Fizzbizz:
  24. // print from 1 to 100, substituting in "FizzBuzz", "Fizz" and "Buzz" when the number in
  25. // question is divisible by 3 and 5, 3 and 5 respectively.
  26. //
  27. void fizzbizz()
  28. {
  29. // @TODO optional "\N:
  30. int i;
  31. for (i=1; i<=100; i++)
  32. {
  33. if ((i%3==0) && (i%5==0))
  34. printf("FizzBuzz");
  35. else if (i%3==0) //3 divides i. 3 is a factor of i
  36. printf("Fizz");
  37. else if (i%5==0)
  38. printf("Buzz");
  39. else
  40. printf("%i",i);
  41. }
  42. }