- 论坛徽章:
- 0
|
#include <stdio.h>
int fun1() { printf("call fun1\n"); }
int fun2() { printf("call fun2\n"); }
int fun3() { printf("call fun3\n"); }
int fun4() { printf("call fun4\n"); }
int fun5() { printf("call fun5\n"); }
typedef int (*fun_t)();
int mask[5] = {1, 2, 16, 8, 4};
fun_t funs[5] = {fun5, fun4, fun1, fun2, fun3};
void test(int num)
{
int i;
for (i = 0; i < 5; i++)
{
if ((num & mask[i]) != 0)
(*funs[i])();
// fun1, fun2, fun3不重复调用
if (i >= 2 && num >= mask[i])
break;
}
}
int main()
{
int num;
for (num = 0; num < 32; num++)
{
printf("num = %d\n", num);
test(num);
printf("\n\n");
}
}
|
怎么样才叫好的方法呢?  |
|