#include<stdio.h>
#include<stdlib.h>
//#include<time.h>
void hanoi(int n,char x,char y,char z);
void move(char x,int n,char y);
int flag=0;
char x,y,z;
int main()
{
int test=1;
int num_disk;
x='A',y='B',z='C';
do
{
printf("Please input the num of disk:");
scanf("%d",&num_disk);
hanoi(num_disk,x,y,z);
printf("Again--1orQuit--0:");
scanf("%d",&test);
}while(test);
system("pause");
return 0;
}
void hanoi(int n,char x,char y,char z)
{
if(n==1)
move(x,1,z);
else
{
hanoi(n-1,x,z,y);
move(x,n,z);
hanoi(n-1,y,x,z);
}
}
void move(char x,int n,char y)
{
printf("%dMove disk %d from %c to %c\n",++flag,n,x,y);
}
#include<stdlib.h>
//#include<time.h>
void hanoi(int n,char x,char y,char z);
void move(char x,int n,char y);
int flag=0;
char x,y,z;
int main()
{
int test=1;
int num_disk;
x='A',y='B',z='C';
do
{
printf("Please input the num of disk:");
scanf("%d",&num_disk);
hanoi(num_disk,x,y,z);
printf("Again--1orQuit--0:");
scanf("%d",&test);
}while(test);
system("pause");
return 0;
}
void hanoi(int n,char x,char y,char z)
{
if(n==1)
move(x,1,z);
else
{
hanoi(n-1,x,z,y);
move(x,n,z);
hanoi(n-1,y,x,z);
}
}
void move(char x,int n,char y)
{
printf("%dMove disk %d from %c to %c\n",++flag,n,x,y);
}