Skip to content

Commit 039ea0f

Browse files
committed
Create toh.c
1 parent 4eac368 commit 039ea0f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

TowerOfHanoi/toh.c

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#include <stdio.h>
2+
3+
void toh(int n, int a, int b, int c)
4+
{
5+
if (n == 0)
6+
return;
7+
toh(n - 1, a, c, b);
8+
printf("Move a disk from rod %d to rod %d\n", a, c);
9+
toh(n - 1, b, a, c);
10+
}
11+
12+
int main()
13+
{
14+
int n = 3;
15+
toh(n, 1, 2, 3);
16+
return 0;
17+
}

0 commit comments

Comments
 (0)