Created
January 3, 2018 18:31
-
-
Save goose121/ea2981078f3961f5d1c01a358ace357a to your computer and use it in GitHub Desktop.
FizzBuzz (function pointers)
This file contains hidden or 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> | |
| void fizz(int i) { | |
| printf("fizz\n"); | |
| } | |
| void buzz(int i) { | |
| printf("buzz\n"); | |
| } | |
| void fizzbuzz(int i) { | |
| printf("fizzbuzz\n"); | |
| } | |
| void p_int(int i) { | |
| printf("%d\n", i); | |
| } | |
| void (*cases[])(int) = {&p_int, &fizz, &buzz, &fizzbuzz}; | |
| void main(void) { | |
| int i; | |
| for(i = 1; i <= 100; ++i) | |
| cases[ ((i % 5 == 0) << 1) + (i % 3 == 0) ](i); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment