اینجا یه وبلاگ مفید برنامه نویسی برای برنامه نویسان ++C و همه علاقه مندان به برنامه نویسیه
/*
  Algorithmic solution is as follows

  1)  if TopN==1, move the single disc from A to C and stop.
  2)  Move the top n-1 discs from A to B, using C as Inter.
  3)  Move the remaining disc from A to C.
  4)  Move the n-1 discs from B to C, using A as destination(dest).
*/

 #include <stdio.h>
 #include <conio.h>
 void tower(int,char,char,char); /*prototype*/
 int main()
   {
   int ndisk;
   clrscr();
   printf("\n Enter number of disks <<<::: ");
   scanf("%d",&ndisk);
   tower(ndisk,'A','B','C');  /*Calling Function*/
   getch();
   return 0;

   } /* End of program */

   /********************************************/

   // src = Source | aux = Auxiliry | dest = Destination
   void tower(int topN, char src,char aux,char dest)
     {
     if(topN == 1)
       {
       printf("\n Disk 1 from %c to %c ",src,dest);
       }
     else
       {
	tower(topN-1,src,dest,aux); //src to aux
	printf("\n Disk %d from %c to %c ",topN,src,dest);
	tower(topN-1,aux,src,dest); //aux to dest
	}
     }
+ نوشته شده در  ساعت   توسط wilyprotozoon  |