2017-10-03 14:12:16 +03:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
// 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);
|
|
|
|
}
|
2017-10-03 14:12:16 +03:00
|
|
|
}
|
2020-05-29 23:23:24 +03:00
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
int noOfDisks;
|
2017-10-03 14:12:16 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
// Asks the number of disks in the tower
|
|
|
|
printf("Number of disks: \n");
|
|
|
|
scanf("%d", &noOfDisks);
|
|
|
|
|
|
|
|
hanoi(noOfDisks, 'A', 'B', 'C');
|
|
|
|
|
|
|
|
return 0;
|
2017-10-03 14:12:16 +03:00
|
|
|
}
|