发新话题
打印

经典递归 C 程序

经典递归 C 程序

void move(char x,char y)
{
  printf("%c>===>===>%c\t\n",x,y);
  }
  void hanoi(int n,char one,char two,char three)
  {
   if(n==1) move(one,three);
   else
   {
   hanoi(n-1,one,three,two);
   move(one,three);
   hanoi(n-1,two,one,three);
   }
   }
   main()

   {
          int m,p;
         for(p=1;p<60;p++)
          printf("*");
     printf("\n input the number of diskes:");
     scanf("%d",&m);
     printf("\nThe step to moving %3d diskes: \n",m);
     hanoi(m,'A','B','C');

     printf("\n*************************************************************************\n");
}
发新话题