Guest User

Untitled

a guest
Dec 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. /** fizzbuzz.c */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <limits.h>
  7.  
  8. #include "fizzbuzz.h"
  9.  
  10. const char* fizzbuzz(signed long n)
  11. {
  12. static char s[20];
  13. s[0] = '\0';
  14. if (n % 15 == 0)
  15. strcat(s, "FizzBuzz");
  16. else if (n % 3 == 0)
  17. strcat(s, "Fizz");
  18. else if (n % 5 == 0)
  19. strcat(s, "Buzz");
  20. else
  21. sprintf(s, "%ld", n);
  22. return s;
  23. }
  24.  
  25. int main()
  26. {
  27. for (int i = 0; i < 100; i++)
  28. printf("%s\n", fizzbuzz(1 + i));
  29. return 0;
  30. }
Add Comment
Please, Sign In to add comment