Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- typedef void (*ptr_to_void_fun)(int);
- ptr_to_void_fun *opts;
- void next(int i) {
- i++;
- int jmp = ((i % 100 == 0) * 4)
- | (((i % 5 == 0) & (i % 3 == 0)) * 3)
- | (((i % 5 == 0) & (i % 100 != 0) & (i % 3 != 0)) * 2)
- | (((i % 3 == 0) & (i % 5 != 0)) * 1);
- (*(opts[jmp]))(i);
- }
- void fizz(int i) {
- printf("Fizz\n");
- next(i);
- }
- void buzz(int i) {
- printf("Buzz\n");
- next(i);
- }
- void fizzbuzz(int i) {
- printf("FizzBuzz\n");
- next(i);
- }
- void printnum(int i) {
- printf("%i\n", i);
- next(i);
- }
- void null(int i) {
- return;
- }
- int main(int argc, char **argv) {
- opts = malloc(sizeof(ptr_to_void_fun) * 5);
- opts[0] = &printnum;
- opts[1] = &fizz;
- opts[2] = &buzz;
- opts[3] = &fizzbuzz;
- opts[4] = &null;
- next(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement