summaryrefslogtreecommitdiff
path: root/algorithms/hanoi.c
diff options
context:
space:
mode:
Diffstat (limited to 'algorithms/hanoi.c')
-rw-r--r--algorithms/hanoi.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/algorithms/hanoi.c b/algorithms/hanoi.c
new file mode 100644
index 0000000..8fa1a28
--- /dev/null
+++ b/algorithms/hanoi.c
@@ -0,0 +1,29 @@
+#include <stdio.h>
+
+
+void hanoi(int hoehe, char von, char nach, char ueber);
+
+int main (void)
+{
+ int n;
+
+ printf ("give height: ");
+ scanf ("%d", &n);
+ printf ("move:\n");
+ hanoi (n, '1', '2', '3');
+ printf ("done!\n");
+
+ return 0;
+}
+
+void
+hanoi(int hoehe, char von, char nach, char ueber)
+{
+ if (hoehe > 1)
+ hanoi (hoehe - 1, von, ueber, nach);
+ printf ("Scheibe '%d' nach '%c',\n",
+ hoehe, nach);
+ if (hoehe > 1)
+ hanoi (hoehe - 1, ueber, nach, von);
+}
+