C语言实现 hanio问题

来源:互联网 发布:淘宝海外直邮要身份证 编辑:程序博客网 时间:2024/05/16 18:07



#include <stdio.h>#include <stdlib.h>int mov(int n,char a ,char b){    printf("number %d  from %c to %c ...\n",n,a,b);    return 0;}int hanio(int n,char a,char b,char c){    if(n==1)        mov(1,a,c);    else    {        hanio(n-1,a,c,b);        mov(n,a,c);        hanio(n-1,b,a,c);    }    return 0;}int main(){//    freopen("1.txt","w",stdout);    int num ;    scanf("%d",&num);    hanio(num,'A','B','C');    return 0;}


0 0
原创粉丝点击