summaryrefslogtreecommitdiff
path: root/algorithms/hanoi.c
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2014-06-15 03:24:33 +0200
committerPatrick Simianer <p@simianer.de>2014-06-15 03:24:33 +0200
commitcf3a29feb5887344b6633ead1b4b6d5657a15a4b (patch)
treef1149508f7305a48dba0226699dfafdd68d81969 /algorithms/hanoi.c
parent5ddc763ab9953eebdaf78af4eb72288d7955b310 (diff)
old stuff: algorithms
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);
+}
+