diff --git a/Tower_of_Hanoi.c b/Tower_of_Hanoi.c new file mode 100644 index 0000000..fa03c76 --- /dev/null +++ b/Tower_of_Hanoi.c @@ -0,0 +1,20 @@ +#include +TOH(int,char,char,char); +void main() +{ + int n; + printf("Enter n :"); + scanf("%d",&n); + TOH(n,'A','B','C'); +} +TOH(int n , char i , char aux , char f) +{ + if(n==1) + { + printf("Move disk from rod %c to rod %c\n",i,f); + return; + } + TOH(n-1,i,f,aux); + TOH(1,i,aux,f); + TOH(n-1,aux,i,f); +}