I used to have a solid knowledge of things. Now pick it up, Hanoi this is the C language to learn things, but the class was really don't understand, until sophomore, just understand that is the way, I feel the programming, really is a window paper, but Pierce to take time to understand absorption.
Topic Description: There is a tower, the tower has a,b,c three pillars. At first, there were n plates on column A, in turn, from large to small, stacked from bottom to top, require all of them to move to the C pillar, in the process can be used to move the B column, but only to move to a plate, and must be three pillars always keep the market at the bottom, small disk in the state. The steps required to move the programming output.
The code is as follows:
Copy Code code as follows:
#include <stdio.h>
int move (char One,char two)//This function is visually displayed for output results, such as when there is only one plate, the output is a-->c. So, move n a plate and show it every step.
{
printf ("%c-->%c\n", one,two);
}
int Hanoi (int n,char One,char Two,char three)//is the core function
{
int move (char One,char two);
if (n==1)//When only one plate is moved directly from column A to pillar C, it is also an exit of the recursive program
Move (One,three);
else{//plate is more than a momentary
Hanoi (N-1,one,three,two)//First use C column to move the upper n-1 plate from column A to column B
Move (One,three); At this point a column only a plate, move to c column can
Hanoi (N-1,two,one,three)//The remaining n-1 plate of column B is moved to column C with the help of a column, and the task is completed.
}
}
int main ()
{
int n;
Char a,b,c;
while (scanf ("%d", &n)!=eof)//You can enter multiple sets of data test results
Hanoi (N, ' a ', ' B ', ' C ');
}