Merge pull request #35 from shashikedissanayake/master

Added a new file
This commit is contained in:
Anup Kumar Panwar 2017-09-22 11:48:29 +05:30 committed by GitHub
commit ffd96f046b

29
TowerOfHanoi.c Normal file
View File

@ -0,0 +1,29 @@
#include <stdio.h>
#include <stdlib.h>
// Function for Tower of Hanoi algorithm
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;
}