fork download
  1. #include <stdio.h>
  2.  
  3. #define FUNC(N) void f##N(void) {printf("from %d\n",N);}
  4. #define f(N) f##N()
  5. // 定義 function
  6. FUNC(0) FUNC(1) FUNC(2) FUNC(3) FUNC(4) FUNC(5) FUNC(6) FUNC(7)
  7. FUNC(8) FUNC(9) FUNC(10) FUNC(11) FUNC(12) FUNC(13) FUNC(14) FUNC(15)
  8. int main()
  9. {
  10. char input[1000];
  11. typedef void (*fptr)(void);
  12. fptr exe_fun[]={f0,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11,f12,f13,f14,f15};
  13.  
  14. printf("input binary code (4bits):");
  15. while(scanf("%s", input)==1){
  16. unsigned dec =
  17. (((input[3]=='1') << 0) |
  18. ((input[2]=='1') << 1) |
  19. ((input[1]=='1') << 2) |
  20. ((input[0]=='1') << 3) );
  21.  
  22. exe_fun[dec]();
  23. printf("input binary code (4bits):");
  24. }
  25. return 0;
  26. }
Success #stdin #stdout 0.01s 1724KB
stdin
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
stdout
input binary code (4bits):from 0
input binary code (4bits):from 1
input binary code (4bits):from 2
input binary code (4bits):from 3
input binary code (4bits):from 4
input binary code (4bits):from 5
input binary code (4bits):from 6
input binary code (4bits):from 7
input binary code (4bits):from 8
input binary code (4bits):from 9
input binary code (4bits):from 10
input binary code (4bits):from 11
input binary code (4bits):from 12
input binary code (4bits):from 13
input binary code (4bits):from 14
input binary code (4bits):from 15
input binary code (4bits):