Created
March 19, 2018 05:42
-
-
Save kuuote/88e0470f80cede6f141696e19846ba4a to your computer and use it in GitHub Desktop.
関数ポインタを利用したFizzBuzz
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> | |
void fizz(int num) | |
{ | |
printf("%s\n", "Fizz"); | |
} | |
void buzz(int num) | |
{ | |
printf("%s\n", "Buzz"); | |
} | |
void fizzbuzz(int num) | |
{ | |
printf("%s\n", "FizzBuzz"); | |
} | |
void printnum(int num) | |
{ | |
printf("%d\n", num); | |
} | |
void (*fizzbuzztable[])(int) = { | |
fizzbuzz, | |
printnum, | |
printnum, | |
fizz, | |
printnum, | |
buzz, | |
fizz, | |
printnum, | |
printnum, | |
fizz, | |
buzz, | |
printnum, | |
fizz, | |
printnum, | |
printnum, | |
}; | |
int main() | |
{ | |
int i; | |
for(i = 1;i <= 100; i++) { | |
fizzbuzztable[i % 15](i); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment