From c5427f877c38e794614451bba8cb1f817ad3b2d0 Mon Sep 17 00:00:00 2001 From: Dev Chouhan <68985102+dev-chouhan@users.noreply.github.com> Date: Sun, 9 Oct 2022 16:23:22 +0530 Subject: [PATCH] Create tower_of_hanoi.c an algorithm examples --- C/tower_of_hanoi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 C/tower_of_hanoi.c diff --git a/C/tower_of_hanoi.c b/C/tower_of_hanoi.c new file mode 100644 index 0000000..ac1edf9 --- /dev/null +++ b/C/tower_of_hanoi.c @@ -0,0 +1,17 @@ +// you got 3 pillars(a,b,c) , first one fully filled and we need to move a to c , we can get the help of b also. +// rules: 1. only one disk at a time. 2. disk's can only be placed on pillars only + +#include + +void TOH (int n, int A, int B, int C){ + if ( n > 0 ){ + TOH (n-1, A, C, B); + printf("(%d , %d)\n",A,C); + TOH (n-1, B, A, C); + } +} + +int main(){ + TOH(16, 1, 2, 3); + return 0; +}