标签:
#include<stdio.h>
//递归函数,汉诺塔
void hanoi(int n,char c1,char c2,char c3);
void move(char x,char y);
int main(){
int i;
printf("move n dishes for A to C,n=");
scanf("%d",&i);
hanoi(i,‘A‘,‘B‘,‘C‘);
return 0;
}
void hanoi(int n,char c1,char c2,char c3){
if(n==1){
move(c1,c3);
}
else {
hanoi(n-1,c1,c3,c2);
move(c1,c3);
hanoi(n-1,c2,c1,c3);
}
}
void move(char x,char y){
printf("%c->%c\n",x,y);
}
标签:
原文地址:http://www.cnblogs.com/zhouyu0-0/p/5439892.html