Saturday, August 20, 2011

Tower of Hanoi

//Tower of Hanoi
#include<stdio.h>
#include<conio.h>
main()
{
      int n;
      void Tower(char beg,char inter,char end,int n);
      printf("Enter how many pins you want to move: ");
      scanf("%d",&n);
      Tower('A','B','C',n);
      getch();
      return 0;
}
void Tower(char beg,char inter,char end,int n)
{
     if (n==1)
     {
              printf("\n%c->%c",beg,end);
              return;
     }
     Tower( beg,end,inter,n-1);
          printf("\n%c->%c",beg,end);
      Tower(inter,beg,end,n-1);     
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More