netoops blog

Sunday 22 September 2013

Tower of Hanoi in C

# include<stdio.h>
# include<conio.h>

void move(int n,char beg,char end,char aux);

void main()
{
 int n;
 clrscr();
 printf("\t\t\t\tTOWER OF HANOI");
 printf("\n\n Enter the number of disks: ");
 scanf("%d",&n);
 printf("\n The disks 1,2,3... are in the increasing order of their sizes.\n\n");
 move(n,'A','B','C');
 getch();
}

void move(int n,char beg,char aux,char end)
{
 if(n>0)
 {
  move(n-1,beg,end,aux);
  printf(" Move disk %d from Peg %c to Peg %c\n",n,beg,end);
  getch();
  move(n-1,aux,beg,end);
 }
}

Tech Knowledege
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments :

Post a Comment

 
Subscribe For Free Updates!

We'll not spam mate! We promise.

Become Our Fan on Social Sites!