Skip to content

Instantly share code, notes, and snippets.

@kazuho
Created September 21, 2023 03:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuho/546895db68255bc06d3679066c0b9747 to your computer and use it in GitHub Desktop.
Save kazuho/546895db68255bc06d3679066c0b9747 to your computer and use it in GitHub Desktop.
simple fizzbuzz in C
#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