打印1~1000.(不使用循环,不使用条件语句)
1 使用函数指针退出
void yesprint(int i);
void noprint(int i);
typedef void(*fnPtr)(int);
fnPtr dispatch[] = { yesprint, noprint };
void yesprint(int i) {
printf("%d\n", i);
dispatch[i / 1000](i + 1);
}
void noprint(int i) { /* do nothing. */ }
int main() {
yesprint(1);
}
void noprint(int i);
typedef void(*fnPtr)(int);
fnPtr dispatch[] = { yesprint, noprint };
void yesprint(int i) {
printf("%d\n", i);
dispatch[i / 1000](i + 1);
}
void noprint(int i) { /* do nothing. */ }
int main() {
yesprint(1);
}