ALL > Computer and Education > courses > university courses > undergraduate courses > An Overview of Computer Science > 2017-2018-1 class > student homework directory >
homework5--艾锦坤 Version 0
👤 Author: by 929165572qqcom 2017-11-23 14:03:20
#include <stdio.h>

int i=1;
void move(int n,char from,char to)
{printf("第%d步:将%d号盘子%c---->%c\n",i++,n,from,to);
}
void hanoi(int n,char from,char denpend_on,char to)
{
if (n==1)
move(1,from,to);
else
{
hanoi(n-1,from,to,denpend_on);
move(n,from,to);
hanoi(n-1,denpend_on,from,to);
}
}
int main()
{
printf("请输入盘子的个数:\n");
int n;
scanf("%d",&n);
char x='A',y='B',z='C';
printf("盘子移动情况如下:\n");
hanoi(n,x,

Please login to reply. Login

Reversion History

Loading...
No reversions found.