#include<stdio.h>
int hanoi(int,char,char,char);
int main()
{
int n;
printf("Enter the number of disks: ");
scanf("%d",&n);
printf("Tower of hanoi for %d disks is:\n",n);
hanoi(n,'A','B','C');
getch();
return 0;
}
int hanoi(int n,char l,char r,char m)
{
if(n>0)
{
hanoi(n-1,l,m,r);
printf("\nMove disk %d from %c to %c",n,l,r);
hanoi(n-1,m,r,l);
}
return 0;
}
int hanoi(int,char,char,char);
int main()
{
int n;
printf("Enter the number of disks: ");
scanf("%d",&n);
printf("Tower of hanoi for %d disks is:\n",n);
hanoi(n,'A','B','C');
getch();
return 0;
}
int hanoi(int n,char l,char r,char m)
{
if(n>0)
{
hanoi(n-1,l,m,r);
printf("\nMove disk %d from %c to %c",n,l,r);
hanoi(n-1,m,r,l);
}
return 0;
}
No comments:
Post a Comment
Convey your thoughts to authors.