[C/C ++] implementation of the tower

Source: Internet
Author: User
/* If there is one plate, move the plate on column A directly from column A to column C. Otherwise, move the n-1 plate on column A to Column B with C, then, move the plate on column A from column A to column C and move the n-1 plate on column B to C with a */# include <stdio. h> void hannuota (int n, char a, char B, char c) {if (1 = N) {// printf ("Move the plate numbered % d directly from the % C column to the % C column \ n", N,, c);} else {hannuota (n-1, A, C, B); // recursion, except for the n-1 plates at the bottom, move from A to bprintf via C ("Move the plate numbered % d directly from % C pillar to % C pillar \ n", n, a, c ); // move the nth number from A to channuota (n-1, B, A, C); // recursively move the n-1 number on B to C .}} Int main () {char character = 'a'; char CH2 = 'B'; char CH3 = 'C'; int N; printf ("Enter the number of plates to move: "); scanf (" % d ", & N); hannuota (n, 'A', 'B', 'C'); Return 0 ;}

 

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.