Skip to content

Instantly share code, notes, and snippets.

@icebreaker
Forked from anshumanatri/towerofhanoi
Created March 12, 2009 12:21
Show Gist options
  • Save icebreaker/78036 to your computer and use it in GitHub Desktop.
Save icebreaker/78036 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