teknoraver

fizzbuzz

Nov 13th, 2018 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.44 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. static const char *vals[] = {
  5.     NULL, NULL, "Fizz", NULL, "Buzz", "Fizz", NULL, NULL,
  6.     "Fizz", "Buzz", NULL, "Fizz", NULL, NULL, "FizzBuzz"
  7. };
  8.  
  9. static void fizzbuzz(int n)
  10. {
  11.     for (int i = 0; i < n; i++)
  12.         if (vals[i % 15])
  13.             puts(vals[i % 15]);
  14.         else
  15.             printf("%d\n", i + 1);
  16. }
  17.  
  18. int main(int argc, char *argv[])
  19. {
  20.     if (argc < 2)
  21.         return 1;
  22.  
  23.     fizzbuzz(atoi(argv[1]));
  24.  
  25.     return 0;
  26. }
  27.  
Add Comment
Please, Sign In to add comment