Created
September 21, 2023 03:02
-
-
Save kazuho/546895db68255bc06d3679066c0b9747 to your computer and use it in GitHub Desktop.
simple fizzbuzz in C
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc, char **argv) | |
{ | |
int maxval; | |
if (argc < 2 || sscanf(argv[1], "%d", &maxval) != 1) { | |
fprintf(stderr, "usage: %s <max-value>\n", argv[0]); | |
exit(1); | |
} | |
for (int i = 1; i <= maxval; ++i) { | |
if (i % 3 == 0) { | |
if (i % 15 == 0) { | |
printf("fizzbuzz\n"); | |
} else { | |
printf("fizz\n"); | |
} | |
} else if (i % 5 == 0) { | |
printf("buzz\n"); | |
} else { | |
printf("%d\n", i); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment