برنامه برج هانوی

sunyboy

New Member
سلام دوستان این برنامه برج هانوی هست که نوشتم که مشکل داره اجرا نمیشه میزارم اینجا از شما میخوام تصریحش کنین برام خیلی ممنونم




PHP:
  # include <iostream.h>
# include <conio.h>
void transfer(int,char,char,char);
int main()
{
int x;
clrscr();
cout<<"WELCOM HANOI\n";
cout<<"number disk?";
cin>>x;
cout<<endl;
transfer (x,'l','r','c');
return 0;
}
void transfer(int x,char from,char to,char temp)
{
if(x>0){
			transfer(x-1,from,temp,to);
			cout<<"move disk"<<x<<"from"<<from<<"to"<<to<<endl;
			transfer(x-1,temp,to,from);
			}
getch();
return 0;
}



ممنونم:rose:
 

the_king

مدیرکل انجمن
الگوریتم تان درست نبود.

کد:
#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void transfer(int x, char *from, char *to, char *temp)
{
	if (x == 1)
	{
      cout << "Move the disk from " << from << " to " << to << endl;
      getch();
   }
   else
   {
		transfer (x - 1, from, temp, to);
		transfer (1, from, to, temp);
		transfer (x - 1, temp, to, from);
	}
}

int main()
{
	int x;
	clrscr();
	cout << "Towers of Hanoi\n";
   cout << "Please enter total number of disks : ";
   cin >> x;
   cout << endl;
   transfer (x, "Left", "Right", "Center");
   getch()
   return 0;
}

کد:
Towers of Hanoi
Please enter total number of disks : [B]4[/B]

Move the disk from Left to Center
Move the disk from Left to Right
Move the disk from Center to Right
Move the disk from Left to Center
Move the disk from Right to Left
Move the disk from Right to Center
Move the disk from Left to Center
Move the disk from Left to Right
Move the disk from Center to Right
Move the disk from Center to Left
Move the disk from Right to Left
Move the disk from Center to Right
Move the disk from Left to Center
Move the disk from Left to Right
Move the disk from Center to Right
 

جدیدترین ارسال ها

بالا