From dbe89ab930128929b5dbb137838b7b83cee22bdf Mon Sep 17 00:00:00 2001 From: shashikedissanayake Date: Thu, 21 Sep 2017 17:47:09 +0530 Subject: [PATCH] added TowerOfHanoi.c --- TowerOfHanoi.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 TowerOfHanoi.c diff --git a/TowerOfHanoi.c b/TowerOfHanoi.c new file mode 100644 index 00000000..ca94f8ab --- /dev/null +++ b/TowerOfHanoi.c @@ -0,0 +1,28 @@ + +#include +#include + +void hanoi(int noOfDisks,char where,char to,char extra){ + if(noOfDisks == 0 ) + { + return; + } + else + { + hanoi(noOfDisks-1, where, extra , to); + printf("Move disk : %d from %c to %c\n",noOfDisks,where,to); + hanoi(noOfDisks-1,extra,to,where); + } +} +int main(void){ + int noOfDisks; + + //Asks the number of disks in the tower + printf("Number of disks: \n"); + scanf("%d", &noOfDisks); + + hanoi(noOfDisks,'A','B','C'); + + return 0; + +} \ No newline at end of file