发布网友 发布时间:2023-10-13 13:40
共1个回答
热心网友 时间:2024-11-25 13:41
#include<stdio.h>追答#include
long step=0;
void hanoi(char a, char b, char c, int n){
if(n==1){
step++;
}else{
hanoi(a,c,b,n-1);
step++;
hanoi(c,b,a,n-1);
}
}
int main(){
int i,n;
printf("n=?");
scanf("%d",&n);
hanoi('A','C','B',n);
printf("%ld\n", step);
return 0;
}