第二周 项目3—汉诺塔

来源:互联网 发布:淘宝开团是不是很难抢 编辑:程序博客网 时间:2024/05/20 20:22
#include <stdio.h>#define discCount 4long move(int, char, char,char);int main(){    long count;    count=move(discCount,'A','B','C');    printf("%d个盘子需要移动%ld次\n", discCount, count);    return 0;}long move(int n, char A, char B,char C){    long c1,c2;    if(n==1)        return 1;    else    {        c1=move(n-1,A,C,B);        c2=move(n-1,B,A,C);        return c1+c2+1;    }}






原创粉丝点击