Merge pull request #66 from AnupKumarPanwar/master

Moved TowerOfHanoi.c to misc
This commit is contained in:
Anup Kumar Panwar 2017-10-03 16:43:46 +05:30 committed by GitHub
commit f65f65a617

View File

@ -1,29 +1,29 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
// Function for Tower of Hanoi algorithm // Function for Tower of Hanoi algorithm
void hanoi(int noOfDisks,char where,char to,char extra){ void hanoi(int noOfDisks,char where,char to,char extra){
if(noOfDisks == 0 ) if(noOfDisks == 0 )
{ {
return; return;
} }
else else
{ {
hanoi(noOfDisks-1, where, extra , to); hanoi(noOfDisks-1, where, extra , to);
printf("Move disk : %d from %c to %c\n",noOfDisks,where,to); printf("Move disk : %d from %c to %c\n",noOfDisks,where,to);
hanoi(noOfDisks-1,extra,to,where); hanoi(noOfDisks-1,extra,to,where);
} }
} }
int main(void){ int main(void){
int noOfDisks; int noOfDisks;
//Asks the number of disks in the tower //Asks the number of disks in the tower
printf("Number of disks: \n"); printf("Number of disks: \n");
scanf("%d", &noOfDisks); scanf("%d", &noOfDisks);
hanoi(noOfDisks,'A','B','C'); hanoi(noOfDisks,'A','B','C');
return 0; return 0;
} }