#include<stdio.h>
void towerOfHanoi(int n, char source, char temp, char dest)
{
if (n == 1)
{
printf("\n Move disk %d from %c to %c",n, source,dest);
return;
}
TowerOfHanoi(n-1, source, dest, temp);
printf("\n Move disk %d from %c to %c", n, source, dest);
towerOfHanoi(n-1, temp, source, dest);
}
void main()
{
int n;
printf("enter the number of disks\n");
scanf("%d",&n);
towerOfHanoi(n, 'A', 'B', 'C');
}
0 Comments