20110112

打印1000,用函数指针数组作为递归的跳出条件

打印1000,用函数指针数组作为递归的跳出条件

#include <stdlib.h>

#include <stdio.h>

void go(void){;}

void quit(void){exit(0);}

void (*where_to_go[2])(void)={go, quit};

void calc(int current, int end)

{

where_to_go[(current-1)/end]();

// printf("%d\t%d\t%d\n", current, end, current/end);

printf("%d\t",current);

calc(++current, end);

}

main()

{

calc(1, 1000);

printf("\n");

}

No comments: