⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hanoi.c

📁 汉诺塔代码,从第一个木桩中,把所有盘子从大到小搬移到第三个木桩中.
💻 C
字号:
/*
*  Name:    $RCSfile$
*
*  Version: $Revision$
*
*  Created by: chensd
*
*  Purpose: This is a C language practice program
*
*  UNICATION CO. LTD. PROPRIETARY INFORMATION
*
*  SECURITY LEVEL - HIGHLY CONFIDENTIAL
*
*  DO NOT COPY
*
*  This document and the information contained in it is confidential and
*  proprietary to Unication Co., Ltd. The reproduction or disclosure in
*  whole or in part, to anyone outside of Unication Co., Ltd. without the
*  written approval of the President of Unication Co., Ltd., under a
*  Non-Disclosure Agreement, or to any employee of Unication Co. Ltd. who
*  has not previously obtained written authorization for access from the
*  individual responsible for the document, will have a significant
*  detrimental effect on Unication Co., Ltd. and is expressly prohibited.
*
*  Copyright (c) $Date$ Unication Co., Ltd.
*
*  All rights reserved
*/

#include <stdio.h> 
#include <stdlib.h>

/*
*  Name:       hanoi
*
*  Purpose:    moving diskes
*
*  Params:     "n" denotes the number of diskes; 
*              "one" denotes the first stake
*              "two" denotes the second stake
*              "three" denotes the third stake
*
*  Note:       none
*
*/
void hanoi(int n,char one,char two,char three)
{ 
    if(n==1) {
		printf("%c->%c\n", one, three);
	}else { 
        hanoi(n-1,one,three,two); 
        printf("%c->%c\n", one, three); 
        hanoi(n-1,two,one,three);
	} 
} 

/*
*  Name:       main
*
*  Purpose:    program entry
*
*  Params:     refer to the usage
*
*  Return:     >0 - succeed
*              -1 - met error
*
*  Note:       none
*
*/
int main(int argc, char **argv)
{ 
    int number; 

	/*input the number of diskes*/
    printf("input the number of diskes:\n");  
    scanf("%d",&number); 
    printf("The step of moving %d diskes:\n",number); 
    hanoi(number,'1','2','3'); 
	
	return 0;
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -