Skip to content

Instantly share code, notes, and snippets.

@kuuote
Created March 19, 2018 05:42
Show Gist options
  • Save kuuote/88e0470f80cede6f141696e19846ba4a to your computer and use it in GitHub Desktop.
Save kuuote/88e0470f80cede6f141696e19846ba4a to your computer and use it in GitHub Desktop.
関数ポインタを利用したFizzBuzz
#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