ParsX.com
پذیرش پروژه از دانشجویی ... تا سازمانی 09376225339
 
   ProfileProfile   Log in to check your private messagesLog in to check your private messages  |  FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups Log inLog in   RegisterRegister 

برجهای هانوی

 
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming
View previous topic :: View next topic  
Author Message
afshin
مهمون يكي دو روزه


Joined: 15 May 2006
Posts: 10

PostPosted: Sat May 27, 2006 8:47 am    Post subject: برجهای هانوی Reply with quote

دوستان عزیز سلام.

از بین شما دوستان کسی هست که بتونه در نوشتان کدهایی برای حل مسئله برجهای هانوی به من کمک کنه ؟؟

اگه امکان داره در مورد نوشتن الگوریتم این مسئله یه کمک به من کمک کنین.

با تشکر
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Sat May 27, 2006 12:55 pm    Post subject: Reply with quote

بصورت بازگشتي :
procedure borj(n:integer;from,help,to:char);
begin
   if n=1 then
      writeln('move mohre from ',from,'to',to)
   else begin
      borj(n-1,from,to,help)
   writeln('move a mohre from ' , from ,'to',to);
   borj(n-1,help,from,to)
   end;{else}
end;

(مقسمي ، ص59،1383)
Back to top
afshin
مهمون يكي دو روزه


Joined: 15 May 2006
Posts: 10

PostPosted: Sat May 27, 2006 4:36 pm    Post subject: Reply with quote

آقا وحید دستت درد نکنه.
با عرض شرمندگی، می تونم خواهش کنم این کدها رو به ++C هم بنویسین ؟؟
من معنی writeln و begin رو نفهمیدم !!

یه تفسیر کوچولو هم می تونین از الگوریتمش برام بنویسین ؟؟؟(اگه زحمتی نیست !!)
Back to top
vahid
بي تو هرگز


Joined: 26 Nov 2004
Posts: 3067
Location: Tehran

PostPosted: Sun May 28, 2006 1:39 pm    Post subject: Reply with quote

بجاي begin و end آكولاد باز و بسته بزار .
براي writeln هم cout \n رو بزن كه يه خط بره پايين .
ميله وسطي help هست . ميله اي كه سمت چپ هست ديكس ها توش هستند .
بكمك help هر بار ديسك ها رو جايگزين مي كني .
Back to top
arash
مدير بخش سي
مدير بخش سي


Joined: 27 Nov 2004
Posts: 1232
Location: www.parsx.com

PostPosted: Mon May 29, 2006 2:14 pm    Post subject: Reply with quote

این به زبان C هستش :
void borj(int n ,char from,char help,char to)
{
   if (n==1)
       printf("move mohre from %c to %c ",from,to) ;
   else {
      borj(n-1,from,to,help);
   printf("move a mohre from %c to %c \n " , from ,to);
   borj(n-1,help,from,to);
  }
}

و این به زبان ++C :

void borj(int n ,char from,char help,char to)
{
   if (n==1)
       cout<<"move mohre from "<<from<<"to"<<to ;
   else {
      borj(n-1,from,to,help);
    cout<<"move a mohre from " << from<<" to "<<to<<"\n";
   borj(n-1,help,from,to);
  }
}
Back to top
afshin
مهمون يكي دو روزه


Joined: 15 May 2006
Posts: 10

PostPosted: Tue May 30, 2006 1:21 pm    Post subject: Reply with quote

ممنون از لطفت.
دستت درد نکنه.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    ParsX.com Forum Index -> C/C++ Programming All times are GMT + 3.5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum