#include<stdio.h>
void towers(int n, char from, char to, char temp)
{
if(n==1)
{
printf("\ndisk 1 moves from %c to %c",from,to);
return;
}
towers(n-1,from,temp,to);
printf("\nDisk %d moves from %c to %c",n,from,to);
towers(n-1,temp,to,from);
}
int main()
{
int n;
printf("Enter the number of disks : ");
scanf("%d", &n);
towers(n,'A','B','C');
return 0;
}
No comments:
Post a Comment