//A Program Desined by Raghav Raj to Solve the Tower Of Hanoi Problem Using Recursive function
#include<stdio.h>
#include<conio.h>
int toh(int,char,char,char);
void main()
{
char source='S',temp='T',dest='D';
int nDisk;
printf("Enter the number of disk: ");
scanf("%d",&nDisk);
printf("\nSequence is : ");
toh(nDisk,source,temp,dest);
getch();
}
int toh(int ndisk,char source,char temp,char dest)
{
if(ndisk>0)
{
toh(ndisk-1,source,dest,temp);
printf("\nMove Disk %d %c-->%c\n",ndisk,source,dest);
toh(ndisk-1,temp,source,dest);
}
}
No comments:
Post a Comment