汉诺塔
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<stdio.h> void mov(char a,char b){ printf("%c->%c\n",a,b); } //将n个盘子从a移到c上,b作为辅助 void hanoi(char a,char b,char c,int n){ if(n>0){ hanoi(a,c,b,n-1); mov(a,c); hanoi(b,a,c,n-1); } } int main(){ hanoi('a','b','c',3); return 0; }
#include<stdio.h> void mov(char a,char b){ printf("%c->%c\n",a,b); } //将n个盘子从a移到c上,b作为辅助 void hanoi(char a,char b,char c,int n){ if(n>0){ hanoi(a,c,b,n-1); mov(a,c); hanoi(b,a,c,n-1); } } int main(){ hanoi('a','b','c',3); return 0; }