Skip to content

Instantly share code, notes, and snippets.

@anshumanatri
Created March 12, 2009 10:13
Show Gist options
  • Save anshumanatri/77994 to your computer and use it in GitHub Desktop.
Save anshumanatri/77994 to your computer and use it in GitHub Desktop.
//Tower of Hanoi
//No of calls made for n disks is equal to pow(2,n) -1.
void hanoi(int n, char a, char c, char b)
{
if(n==1)
{
printf("\nShift disk 1 from %c to %c",a,c);
return ;
}
hanoi(n-1,a,b,c);
printf("\nShift disk %d from %c to %c" ,n,a,c);
hanoi(n-1,b,c,a);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment