我用递归算法写了个汉诺塔的程序 为什么圆盘超过9个就不对了
# include <stdio.h>void hannuota(char ch1, char ch2, char ch3, int n)
{
if (n == 1)
printf("第%d个盘从%c放到%c\n", n, ch1, ch3);
else
{
hannuota(ch1, ch3, ch2, n-1);
printf("第%d个盘从%c放到%c\n", n, ch1, ch3);
hannuota(ch2, ch1, ch3, n-1);
}
return;
}
int main(void)
{
char ch1 = 'A';
char ch2 = 'B';
char ch3 = 'C';
int n;
printf("输入个数:");
scanf("%d", &n);
hannuota(ch1, ch2, ch3, n);
return 0;
}