打印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);
}

相关文章:

  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2021-04-05
  • 2022-01-02
  • 2021-11-10
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案