From f9e31c9307839d95ea268811fa55252cbb85599d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=86=80=E9=B9=8F?= <37091248+Jipeng416@users.noreply.github.com> Date: Wed, 21 Mar 2018 18:17:18 +0800 Subject: [PATCH] Create hanoi --- level1/p08_hanoi/hanoi | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 level1/p08_hanoi/hanoi diff --git a/level1/p08_hanoi/hanoi b/level1/p08_hanoi/hanoi new file mode 100644 index 00000000..cf4527b7 --- /dev/null +++ b/level1/p08_hanoi/hanoi @@ -0,0 +1,30 @@ +#include +void Move(int n,char a,char b); +void Hanoi(int n,char a,char b,char c) +{ + if (n==1) + { + Move(n,a,c); + } + else + { + Hanoi(n-1,a,c,b); + Move(n,a,c); + Hanoi(n-1,b,a,c); + } +} +int x; +void Move(int n,char a,char b) +{ + x++; + printf("The %d step: Move No.%d dish from %c post to %c post \n" ,x,n,a,b); +} +int main() +{ + int n; + printf("Please input the number of floor:\n"); + scanf(" %d",&n); + Hanoi(n, 'A', 'B', 'C'); + return 0; +} +