CODE FOR TOH(Tower Of Hanoi)
"Nice One Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
TOH(int n,char beg,char aux,char end)
{
if(n>=1){
TOH(n-1,beg,end,aux);
printf("%c to %c \n",beg,end);
TOH(n-1,aux,beg,end);
}
}
void main()
{ clrscr();
char A='A',B='B',C='C';
TOH(3,A,B,C);
getch();
}
"Nice One Program"
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
TOH(int n,char beg,char aux,char end)
{
if(n>=1){
TOH(n-1,beg,end,aux);
printf("%c to %c \n",beg,end);
TOH(n-1,aux,beg,end);
}
}
void main()
{ clrscr();
char A='A',B='B',C='C';
TOH(3,A,B,C);
getch();
}
No comments:
Post a Comment