pleasehelpme
Member
اینم برج هانوی:
کد:
#include<iostream.h>
#include<conio.h>
void move(int n,char f,char m,char l);
void main(){
const char b1='a',b2='b',b3='c';
int num;
clrscr();
cout<<"Please enter the number of halghe:";
cin>>num;
move(num,b1,b2,b3);
getch();
}
void move(int n,char f,char m,char l)
{
if(n<=1)
cout<<"Move "<<f<<" to "<<l<<'\n';
else
{
move(n-1,f,l,m);
move(1,f,m,l);
move(n-1,m,f,l);
}
}