下面是在一个4*4的数组中随意输入坐标,然后在该坐标和该坐标所在的行,该坐标所在的列,和两条斜线上全部赋'*'(星号字符),我晕,现在为什么当坐标为(2,2)时,坐标(1,0)的位置也出现星号,那位大哥看看,怎么回事
#include <stdio.h>
#include <conio.h>
#define N 4
int main(void)
{
char a[N][N];
int i, j, k, m, n;
for (m = 0; m < N; m++)
{
for (n = 0; n < N; n++)
{
a[m][n] = ' ';
}
}
printf("Enter position i and j: ");
scanf("%d %d", &i, &j);
a[i][j] = '*'; /* a[2][1] = '*' */
for (k = 0; k < N; k++) /* horizontal */
{
a[i][k] = '*';
}
for (k = 0; k < N; k++) /* vertical */
{
a[k][j] = '*';
}
m = i; n = j; /* left top */
while (m > 0 && n > 0)
{
a[--m][--n] = '*';
}
m = i; n = j; /* right bottom */
while (m < N && n < N)
{
a[++m][++n] = '*';
}
m = i; n = j; /* right top */
while (m > 0 && n < N)
{
a[--m][++n] = '*';
}
m = i; n = j; /* left bottom */
while (m < N && n > 0)
{
a[++m][--n] = '*';
}
for (m = 0; m < N; m++)
{
putchar('\n');
for (n = 0; n < N; n++)
{
if (a[m][n] == '*')
{
putchar('*');
putchar(' ');
}
else
{
putchar('@');
putchar(' ');
}
}
}
getch();
return 0;
}