// Hanoi.cpp : Defines the entry point for the console application. // #include "stdafx.h" //#include <stdio.h> int main() { void hanoi(int n,char one,char two,char three); // 对hanoi函数的声明 int m; printf("input the number of diskes:"); scanf("%d",&m); printf("The step to move %d diskes:\n",m); hanoi(m,'A','B','C'); return 0; } void hanoi(int n,char one,char two,char three) // 定义hanoi函数 // 将n个盘从one座借助two座,移到three座 { //void move(char x,char y); // 对move函数的声明 if(n==1) //move(one,three); printf("%d:%c->%c\n",n,one,three); else { hanoi(n-1,one,three,two); //move(one,three); printf("%d:%c->%c\n",n,one,three); hanoi(n-1,two,one,three); } } /* input the number of diskes:3 The step to move 3 diskes: 1:A->C 2:A->B 1:C->B 3:A->C 1:B->A 2:B->C 1:A->C Press any key to continue */