morteza_ss
29-05-2011, 10:33
اينم سورس الگوريتم هانوي اميدوارم لذت ببريد.
#include <iostream>
#include <stdio.h>
#include <conio.h>
void tower(int,char,char,char);
int main()
{
int n;
clrscr();
cout<<" :::: WELCOME ::::\n";
cout<<":::::::Borj Hanoy:::::::"<<endl<<endl;
cout<<"Enter number of loops (Halghe) :";
scanf("%d",&n);
tower(n,'A','B','C');
getch();
return 0;
}
void tower(int topN, char src,char aux,char dest)
{
if(topN == 1)
{
printf("\n Loop 1 from %c to %c ",src,dest);
}
else
{ tower(topN-1,src,dest,aux);
printf("\n Loop %d from %c to %c ",topN,src,dest);
tower(topN-1,aux,src,dest);
}
}
بچه ها اينو برام بنويسيد وقت ندارم ثواب داره:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید
#include <iostream>
#include <stdio.h>
#include <conio.h>
void tower(int,char,char,char);
int main()
{
int n;
clrscr();
cout<<" :::: WELCOME ::::\n";
cout<<":::::::Borj Hanoy:::::::"<<endl<<endl;
cout<<"Enter number of loops (Halghe) :";
scanf("%d",&n);
tower(n,'A','B','C');
getch();
return 0;
}
void tower(int topN, char src,char aux,char dest)
{
if(topN == 1)
{
printf("\n Loop 1 from %c to %c ",src,dest);
}
else
{ tower(topN-1,src,dest,aux);
printf("\n Loop %d from %c to %c ",topN,src,dest);
tower(topN-1,aux,src,dest);
}
}
بچه ها اينو برام بنويسيد وقت ندارم ثواب داره:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید