您的位置:首页 > 其它

奇妙的递归程序-----台阶问题

2010-05-09 13:24 330 查看
#define STAIR_NUM 5

int total=0;

int index;

int que[STAIR_NUM];

void outputstep()

{

int i;

for(i=0;i<index;i++)

printf("-%d",que[i]);

printf("-/n");

}

void step(int n)

{

if (n==0)

{

total++;

printf("---------the NO.%d ----------/n",total);

outputstep();

return ;

}

que[index++]=1;

step(n-1);

--index;

if (n>1)

{

que[index++]=2;

step(n-2);

--index;

}

if(n>2)

{

que[index++]=3;

step(n-3);

--index;

}

}

main()

{

printf("/n");

printf("--------------------------------------/n");

printf(" stair step /n");

printf("--------------------------------------/n");

step(STAIR_NUM);

printf("/n the total is %d /n",total);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: