//Tower Of Hanoi.
#include<stdio.h>
main()
{
char A,B,C;
int n;
void TOH(char,char,char,int);
printf("Enter No Of disc of TOH\n");
scanf("%d",&n);
TOH('A','B','C',n);//Alert when you pass character then it must be in
//single qoute otherwise it will pass garbage value;
}
void TOH(char t1,char t2,char t3,int n)
{
if(n<=0)
printf("Negative Entry is Wrong\n");
else if(n==1)
printf("Move TOP disk from tower %c to tower %c\n\n",t1,t3);
else
{
TOH(t1,t3,t2,n-1);
TOH(t1,t2,t3,1);
TOH(t2,t1,t3,n-1);
}
}
No comments:
Post a Comment