Created
May 16, 2019 11:35
-
-
Save manojnaidu619/cea8f63975be18d0489829836796b2de to your computer and use it in GitHub Desktop.
Solving Tower of Hanoi in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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