Solution to the problem of Hanoi Tower

Source: Internet
Author: User

Hanoi tower problem Moving N plates can be converted to first move the N-1 plate to B, then the last plate to move to C, and finally the N-1 plate on the B to move to C; N-1 plates move and move N-1 plates the same way, just change C to B, the last plate to move to C , N-1 a plate and moving from B to B.

#include <stdio.h>
#include <stdlib.h>
Hanoi Tower Problem
void Hanoi (int n,char A,char B,char c)
{
if (n==1)
printf ("%c->%c\n", a,c);
Else
{
Hanoi (N-1,A,C,B);
printf ("%c->%c\n", a,c);
Hanoi (N-1,B,A,C);
}
}
int main ()
{
int m;

printf ("Please enter the number of plates: \ n");
scanf ("%d", &m);
printf ("The process of plate movement is: \ n");
Hanoi (M, ' a ', ' B ', ' C ');
System ("pause");
return 0;
}

does not show full

Solution to the problem of Hanoi Tower

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.