Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created May 16, 2019 11:35
Show Gist options
  • Save manojnaidu619/cea8f63975be18d0489829836796b2de to your computer and use it in GitHub Desktop.
Save manojnaidu619/cea8f63975be18d0489829836796b2de to your computer and use it in GitHub Desktop.
Solving Tower of Hanoi in C
#include <stdio.h>
int count=0;
void hanoi(int n,char from,char to,char aux){
if(n>0){
hanoi(n-1,from,aux,to);
++count;
printf("Disk %d from %c -> %c\n",n,from,to);
hanoi(n-1,aux,to,from);
}
}
int main(){
int n;
printf("Enter no of Plates : ");
scanf("%d",&n);
hanoi(n,'A','C','B');
printf("\n%d steps involved!",count);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment