Hanoi Tower Problem

Source: Internet
Author: User

Problem:

Hanoi

#include <stdio.h> #include <stdlib.h>void Hanoi (int N, char A, Char B, char C);/* Run this program using the C Onsole Pauser or add your own getch, System ("pause") or input loop */int main (int argc, char *argv[]) {int n;scanf ("%d", & Amp;n);p rintf ("The Step to move%2d dishes are:\n", N), Hanoi (N, ' A ', ' B ', ' C '); return 0;} void Hanoi (int N, char A, char B, char C) {if (n==1) printf ("Move dish%d from%c to%c\n", N, A, c); Else{hanoi (N-1, A, C, b) The//a uses C to transfer the remaining N-1 plates to the bprintf ("Move dish%d from%c to%c\n", N, A, c), Hanoi (N-1, B, A, c);//b with a n-1 plates to c}}/*5the step to M Ove 5 Dishes Are:move dish 1 from A to Cmove Dish 2 from A to bmove dish 1 from C to bmove Dish 3 from A to Cmove dish 1 From-B to Amove-dish 2 from-B to cmove dish 1 from-A to Cmove-dish 4 from-A to bmove-1 from-C to dish-bmove 2 from C To Amove Dish 1 from B to Amove Dish 3 from C to bmove Dish 1 from A to Cmove Dish 2 from A to bmove dish 1 from c to Bmov E dish 5 from A to Cmove Dish 1 from B to Amove Dish 2 frOm B to Cmove dish 1 from-A to Cmove dish 3 from-B to amove dish 1 from-C to bmove Dish 2 from-C to Amove-dish 1 from-B to Amove Dish 4 from B to Cmove Dish 1 from A to Cmove Dish 2 from A to bmove dish 1 from C to bmove Dish 3 from A to Cmove Dish 1 from-B to Amove-dish 2 from-B to Cmove-dish 1 from A to C--------------------------------*/


Hanoi Tower Problem

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.