【文件属性】:
文件名称:C Language.
文件大小:1KB
文件格式:NONE
更新时间:2012-03-03 16:08:11
C language
#include /*Call then stdio.h head program*/
#define INIT_NUM 2 /*define a number to the stack*/
int count; /*count then steps*/
void hanoi(int n,char from,char to,char middle) /*The hanoi(int,char,char,char) son program*/
{
if(n>0)
{
count++;
hanoi(n-1,from,middle,to);
printf("Move NO.%d from %c to %c\n",n,from,to);
hanoi(n-1,middle,to,from);
}
}
/*
define A,B and C as the Hanois,
A is the From hanoi,
B is the goal hanoi,
C is the middle hanoi.
*/
void main() /*The mai() program*/
{
int init=INIT_NUM; /*initialize the number of a stack*/
printf("A is the begin,B is the Goal,C is the middle Goal.\n"); /*Note.*/
hanoi(init,'A','B','C'); /*Recall the hanoi(int,char,char,char) program*/
printf("\nCount= %d",count); /*Output the steps message*/
getch(); /*For you can see the .EXE screen*/
return NULL;
}