您的位置:首页 > 其它

汉诺塔问题

2018-01-30 16:28 246 查看
#include <stdio.h>

#include <conio.h>

int main(){

  void hanoi(int n,char one,char two,char three);

  int m;

  printf("输入层数");

  scanf("%d",&m);

  printf("移动%d层的步骤为:\n",m);

  hanoi(m,'A','B','C');

  getch();



void hanoi(int n,char one,char two,char three){

  void move(char x,char y);

  if(n==1)

    move(one ,two);

  else{

    hanoi(n-1,one,two,three);

    move(one,three);

    hanoi(n-1,two,one,three);

  }



void move(char x,char y){

  printf("%c-->%c\n",x,y);
}

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