求大神指导 为什么和视频演示的结果不一样
#define _CRT_SECURE_NO_WARNINGSint a[10][3] = { 0 };
#include<stdio.h>
#include<stdlib.h>
void show(int a[10][3]);
void hanno(int n, char A, char B, char C);
void Move(char X, char Y);
void main()
{
int a[10][3] = { 0 }; //存储
int n;
printf("请输入汉诺塔层数:");
scanf("%d", &n);
for (int i = 0; i < n; i++) //控制
{
a[10 - 1 - i][0] = n - i; // 布局
}
show(a); //显示
hanno(n, 'A', 'B', 'C');
system("pause");
}
void show(int a[10][3])
{
printf("%5c%5c%5c\n", 'A', 'B', 'C');
printf("---------------------- \n");
for (int i = 0; i < 10; i++) //行
{
for (int j = 0; j < 3; j++) //列
{
printf("%5d", a[i][j]); //显示
}
printf("\n");
}
}
void hanno(int n, char A, char B, char C)
{
if (n<1)
{
return;
}
else if (n == 1)
{
printf("\n%c->%c", A, C);//n==1时直接A->C
Move(A, C);
show(a);
}
else
{
hanno(n - 1, A, C, B);
printf("\n%c->%c", A, C);//n==1时直接A->C
Move(A, C);
show(a);
hanno(n - 1, B, A, C);
}
}
void Move(char X, char Y) //'A'=65, 'B'=66, 'C'=67
{
int m = X - 65;
int n = Y - 65;
int imove = -1;
int jmove;
int temp;
for (int i = 0; i < 10; i++)
{
if (a[i][m] != 0)
{
imove = i;
break;
}
}
if (a[9][n] == 0)
jmove = 9;
else
{
jmove = 10;
for (int i = 0; i < 10; i++)
{
if (a[i][n] != 0)
{
jmove = i;
break;
}
}
jmove -= 1;
}
temp = a[imove][m];
a[imove][m] = a[jmove][n];
a[jmove][n] = temp;
}
为什么数组的的值没有交换?