ALL > Computer and Education > courses > university courses > undergraduate courses > An Overview of Computer Science > ZSTU-2016-2017-CLASS > huanglican > 林烨如2016329621054 >
homework5汉诺塔 Version 0
👤 Author: by 614399835qqcom 2016-11-29 18:26:00
#include<stdio.h>
int sum;
void move(char A,char B)
{
sum++;
printf("%c-->%c\n",A,B);
}
void hanoi(char A,char B,char C,int n)
{
if(n==1)
move(A,C);
else
{
hanoi(A,C,B,n-1);
move(A,B);
hanoi(B,A,C,n-1);
}
}
void main()
{
int n;
scanf("%d",&n);
sum=0;
hanoi('A','B','C',n);
printf("%d\n",sum);
}

Please login to reply. Login

Reversion History

Loading...
No reversions found.