Problem A: 深入浅出学算法022-汉诺塔问题II

#include<stdio.h>
void hanio(int n,char a,char b,char c)
{
    if(n==1)
    printf("%c->%c\n",a,c);
    else{
        hanio(n-1,a,c,b);
        printf("%c->%c\n",a,c);
        hanio(n-1,b,a,c);
    }
}
int main(void)
{
    int n;
    n>=1&&n<=10;
    while(scanf("%d",&n)!=EOF){
    hanio(n,'a','b','c');}
    return 0;
}

 

posted @ 2018-12-17 16:21  MichaelCecil  阅读(2098)  评论(0编辑  收藏  举报