Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define DIVTHREE 1
- #define DIVFIVE (1<<2)
- #define DIVBOTH (DIVTHREE | DIVFIVE)
- #define DIVNEITHER 0
- int main(int argc, char *argv[])
- {
- long int start, end, current;
- char *endp;
- if (argc < 2) {
- fprintf(stderr, "usage: %s <start> <end>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
- start = strtol(argv[1], &endp, 10);
- if (endp == argv[1]) {
- fprintf(stderr, "invalid start number.\n");
- exit(EXIT_FAILURE);
- }
- end = strtol(argv[2], &endp, 10);
- if (endp == argv[2]) {
- fprintf(stderr, "invalid end number.\n");
- exit(EXIT_FAILURE);
- }
- if (end < start) {
- fprintf(stderr, "end number should not be less than start.\n");
- exit(EXIT_FAILURE);
- }
- for (current = start; current <= end; current++) {
- switch ( (current % 3 ? 0 : DIVTHREE) |
- (current % 5 ? 0 : DIVFIVE) ) {
- case DIVTHREE:
- printf("fizz\n");
- break;
- case DIVFIVE:
- printf("buzz\n");
- break;
- case DIVBOTH:
- printf("fizzbuzz\n");
- break;
- case DIVNEITHER:
- printf("%ld\n", current);
- break;
- default:
- fflush(stdout);
- fprintf(stderr, "your CPU is broken.\n");
- exit(EXIT_FAILURE);
- }
- }
- exit(EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement