From cf3a29feb5887344b6633ead1b4b6d5657a15a4b Mon Sep 17 00:00:00 2001 From: Patrick Simianer Date: Sun, 15 Jun 2014 03:24:33 +0200 Subject: old stuff: algorithms --- algorithms/hanoi.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 algorithms/hanoi.c (limited to 'algorithms/hanoi.c') 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 + + +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); +} + -- cgit v1.2.3