/* TOWERS OF HONOI */
#include<stdio.h>
#include<conio.h>
void tower(int,char,char,char);
main()
{
int n;
char s='a',t='b',d='c';
clrscr();
printf("\n Enter no.of discs \t:");
scanf("%d",&n);
tower(n,s,t,d);
getch();
}
void tower(int n,char s,char t,char d)
{
if(n==1)
{
printf("\n %c->%c \n",s,d);
return;
}
tower(n-1,s,d,t);
printf("\n %c->%c \n",s,d);
tower(n-1,t,s,d);
}
No comments:
Post a Comment