汉诺塔的C语言实现

汉诺塔的C语言实现,第1张

概述汉诺塔的C语言实现

下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。

内存溢出小编现在分享给大家,也给大家做个参考。

/* * this file is the implementation of hanoi game * file name: hanoi.c * author: John Woods * date: 2015/05/30 * statement: anyone can use this file for any purpose */#include <stdio.h>#include <stdlib.h> //function declarationsvoID hanoi(int n,char x,char y,char z);voID move(int n,char y); //program entranceint main(voID) {    char c;    int n = 0; //the height of hanoi    printf("please input the height of hanoi:");    while(!scanf("%d",&n)) {        while((c=getchar())!='\n' || c!=EOF);        printf("bad input! try again:");    }    hanoi(n,'x','y','z');    return 0;}  //function implementationsvoID hanoi(int n,char z) {    if(1 == n) {        move(1,x,z);    } else {        hanoi(n-1,z,y);        move(n,z);        hanoi(n-1,y,z);    }} voID move(int n,char z) {    printf("move disk %d from %c to %c\n",n,z);}

以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

总结

以上是内存溢出为你收集整理的汉诺塔的C语言实现全部内容,希望文章能够帮你解决汉诺塔的C语言实现所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1232307.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存